Musings of Geekdom by Eric Newton

tail /var/log/thoughts
posts - 88 , comments - 41 , trackbacks - 68

Ajax Post on Safari 11.4 timing out for strange reasons? Check here

This was a little doozy.

We have a site that has ajax file upload fields that worked for all browsers, IE, Firefox, Chrome, Safari except for one instance: Safari on iPhones.

How strange!  The problem exhibited was that Safari would start the request but never seem to attempt to finish and no matter what timeout, would timeout after 60 seconds (the max I believe you can set).  Note that using a traditional POST would work fine, but who wants that in 2018/2019???

Turns out there's an odd little bug in Safari on iOS 11.4... if you have input type=file with no file selected, Safari sets up to upload zero bytes, and just does nothing.

The fix is a bit odd too... when you have an <input type=file> field with no file selected, you need to use new FormData() to remove it before submitting the request.

[sample code to come]
basically check the field via javascript before ajax post, examine the size property.  If its 0, you now know that there's no file selected, so you have to remove that field from the FormData collection.

Seems to have been fixed after iOS 11.4.

Print | posted on Sunday, February 17, 2019 1:10 AM | Filed Under [ ios safari jQuery timeout ajax ]


Comments are closed.
Comments have been closed on this topic.

Powered by: