ajax form submit not working on iPhone Safari

2019-08-09 01:15发布

问题:

I have created a form allowing the user to select a photo. Upon selection, the form is submitted automatically via ajax (as opposed to having a standard submit button). It works fine in all browsers, but it does not work on the mobile version of safari.

My HTML:

<form id="myForm" action="php/upload.php" method="post">
<input name="uploadedfile" type="file" id="uploadPhotoButton"/>
</form>

My javascript:

$(':file').change(function(){
    var formData = new FormData($('form')[0]);
    $.ajax({
        url: 'php/upload.php',  //server script to process data
        type: 'POST',
        success: uploadComplete,
        // Form data
        data: formData,
        //Options to tell JQuery not to process data or worry about content-type
        cache: false,
        contentType: false,
        processData: false
    });
});

On iPhone Safari, the change handler function is called fine, but the ajax call fails.

Any suggestions?

回答1:

So it appears that in iOS6, safari caches post calls... The solution is here: Is Safari on iOS 6 caching $.ajax results?