Why is Ajax returning 'error' but running 'success' in Firefox?
$.ajax({ type: "POST", url: "test.php", data: 'action='+action+'&workOrderID='+value+'&wid='+wid+'&eid='+eid+'&lastName='+lastName+'&firstName='+firstName+'&finalComment='+comment, cache: false, complete: function(data) { alert("Work Order Updated"); console.log("success"); console.log(data); }, error: function(xhr, ajaxOptions, thrownError) { alert("Work Order NOT Updated"); console.log("error"); console.log(xhr); console.log(ajaxOptions); console.log(thrownError); } });
Hi all,
This is my dilemma: on Chrome, Edge, and Internet Explorer the AJAX call returns with only a success, runs the following query and everything is good. BUT, in Firefox, the AJAX call returns with an error in the console log, eventually being fired a second time (not intended) to return success, thus beginning the query etc... with the alert being signaled with the "error".
I am trying to solve this problem from an end user perspective. The function is running, but if the alert is returning with an error the user will not know if they did their job correctly.
I have included the console log for those who know would like to see what is happening. I am still a rookie with AJAX, I can edit the post if there is additional information needed or if there is an issue with the code.
Hum I was facing this kind of issue a while ago. The answer for me was to set the MIME type of the ajax request. Set :
contentType: 'application/json'
If jquery doesn't find the contentType or if it is invalid, it will fire an error
Of course set this content type if you are handling JSON.
Otherwise you can put 'plain/text' and do a JSON.parse(), but it's a little dirty
链接地址: http://www.djcxy.com/p/55870.html