ajax表单提交不适用于iPhone Safari

时间:2022-11-24 11:10:18

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.

我创建了一个允许用户选择照片的表单。选择后,表单将通过ajax自动提交(而不是使用标准的提交按钮)。它适用于所有浏览器,但它不适用于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.

在iPhone Safari上,更改处理程序函数被称为罚款,但ajax调用失败。

Any suggestions?

1 个解决方案

#1


0  

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

所以看来在iOS6中,safari缓存后调用...解决方案就在这里:iOS 6上的Safari缓存$ .ajax结果吗?

#1


0  

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

所以看来在iOS6中,safari缓存后调用...解决方案就在这里:iOS 6上的Safari缓存$ .ajax结果吗?