Question

This is my current code, for uploading and posting data to modal window. Affcourse it works pefrect in IE 10, Chrome, Firefox, Opera... except it doesn't works in IE < 10. Have someone any ideas how should i solve this "bug" or how would i say it is.

$(document).ready(function () {
   $("form[id='form']").submit(function(e) {
      var formData = new FormData($(this)[0]);
      $('#myModal').modal('show');   
      $.ajax({
         url: "home/add_store/post",
         type: "POST",
         data: formData,
         async: false,
         success: function (data) {
            $('#body').html(data);
         },
         cache: false,
         contentType: false,
         processData: false
      });
      e.preventDefault();
   });
});

On webs i found about FormData that it isnt really supported in IE < 10, is there any way that i can still use this?

Était-ce utile?

La solution

Found solution that works also on older browsers. I use jquery form script. Here is code:

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="myfile" multiple><br>
<input type="text" name="text"><br>
<input type="submit" value="Upload File to Server">
</form>
<div id="status"></div>

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script>

$('form').ajaxForm({
    complete: function(xhr) {
        $('#status').html(xhr.responseText);
    }
}); 

</script>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top