This code worked very well and quickly for many years.
Given that $ .ajax does not receive any files, since upgrading to iOS 11.3 this $ .ajax has been running very slowly for up to 20 seconds to send a simple text form when testing in the iOS browser.
But if a file element transfers file data, $ .ajax works fine in both cases and as fast as expected.
HTML ---
<form enctype="multipart/form-data" id="chatform" method="post">
<input type="file" name="pic" id="pic" class="hidden" />
<textarea name="chattextarea" id="chattextarea" rows="3" cols="10"></textarea>
<input type="button" value="Send" onclick="sendMessage();" />
</form>
JavaScript ---
function sendMessage() {
var formData = new FormData($("#chatform")[0]);
$.ajax({
url: 'send.php',
type: 'POST',
data: formData,
async: true,
cache: false,
contentType: false,
processData: false,
success: function (returndata) {
}
});
}
Is this a bug in iOS 11.3?
----- EDIT -----
Yes, indeed, this is not only an iOS 11.3 bug, but also a Safari 11.1 bug. While I tested these environments and replicated the error:
- Mac OS, Safari
- iOS, Safari
- iOS Chrome
- iOS, WKWebView (hybrid application)
I wrote a simple workaround, please check my answer and let me know if you have a cleaner solution.