2021-06-26

AJAX request works on desktop (chrome), gives 409 error on IOS (safari)

I'm doing a simple intercept of an html form submit and manually POSTing the result using AJAX. This works fine on desktop but fails on IOS with a 409 conflict error. My understanding is this indicates that multiple POSTs are being sent simultaneously and conflicting with each other.

I have searched far and wide for solutions and I have all the necessary measures to prevent double submits, as far as I can tell they should not be occurring. Yet I still get this error. I have tried the following

  • e.preventDefault() in submit handler
  • e.stopImmediatePropagation() in submit handler
  • return false in submit handler
  • adding an additional onsubmit="return false" to the form element
  • cache:false in ajax options and adding ?x=[randomnumber] to the url, to make sure I'm getting new results
  • async:true in ajax options
  • crossDomain:false in ajax options
  • Confirm with debug logs that only one form is being sent via my submit handler and ajax call
  • Using both and absolute and relative URL

here's the gist of my code

<form id="myform" onsubmit="return false">
    ... form fields 
    <input type="submit"value="Submit"> 
</form>
var form = $('#myform')
form.on('submit', function(e) {
    e.preventDefault()
    e.stopImmediatePropagation()
    var data = $(this).serialize()
    var url = `php/contact-us.php?nocache=${Date.now()}`

    $.ajax({
        url: url, 
        data: data,
        cache: false,
        async:true,
        crossDomain:false,
        dataType:'text',
        type: 'POST',
        success: function(data){
            alert(data);
        },
        error: function(xhrRequest, status, error) {
            alert(`There was an error submitting your request (${xhrRequest['status']}).`)
        }
    });
    return false
})

I get the successful alert on desktop (chrome) and "There was an error submitting your request (409)" on mobile (safari). Why might this be happening?



from Recent Questions - Stack Overflow https://ift.tt/35Rev1k
https://ift.tt/eA8V8J

No comments:

Post a Comment