Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AjaxForm not working in Safari and Chrome

This javascript works in FF but not safari or Chrome:

$('#image').change(function() {
    $('#imageform').ajaxForm({
       target: '#preview',
       success: function() { 
          alert('works!');
       }
    }).submit();
});

Here is the HTML form:

<form id="imageform" method="post" enctype="multipart/form-data" action="/admin/ajaxImage/">

Please help me get it to work in Safari and Chrome!

EDIT:

I found my problem. I have a form inside a form, which prevents it from working. Thank you all for all of your suggestions.

like image 778
user1435853 Avatar asked Jan 28 '26 20:01

user1435853


2 Answers

you should use the ajaxSubmit function, the code to send a POST a request:

$("#imageform").ajaxSubmit({
    url: 'ServerSidePage.php',
    type: 'post',
    success: function() 
    { 
      alert("works!");
    }
});

EDIT: might check this out also:

$('#imageform').ajaxForm({
  success: function(response, statusText) {
    $('#preview').html(response);
  }
});

i don't know what "#preview" is, might change it to "append" or whatever you need.

like image 73
Or Duan Avatar answered Jan 31 '26 09:01

Or Duan


Calling .ajaxForm() sets up event listeners to handle submissions.
You should never call it more than once.

To use invoke the plugin by hand, call ajaxSubmit() instead.

For more information, see the documentation.

like image 43
SLaks Avatar answered Jan 31 '26 09:01

SLaks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!