Ajax post being aborted by firefox (not seen in Chrome or IE)
Asked Answered
S

9

19

When using firefox, an ajax post request i have is being reported as aborted in firebug. The ajax post works fine in IE and Chrome. It is not a cross domain request. I tried looking at the issue using fiddler, and when fiddler is capturing web traffic (with options set to decrypt https) the post works. The post issue cannot be created in my local development environment, as all Firefox attempts successfully post the data I'm sending via ajax. Any idea why the post works while fiddler is running? It might give me some idea of how to get it working.

$.ajax({
            type: 'POST',
            url: '/Save',
            data: JSON.stringify(dataset),
            datatype: "html",
            contentType: "application/json",
            success: function (data, textStatus, jqXHR) {
                //alert("success");
            },
            error: function (jqXHR, textStatus, errorThrown) {
                //alert("error");
            }
        });

Also, this ajax request is called by a number of methods, and only when the largest of the datasets is sent does it fail.

Solley answered 30/10, 2012 at 22:27 Comment(9)
How long (clock time) does the request take? Is it possible that the request is timing out?Sitting
Is this request https? And, if you view the dataset after the stringify, is it properly formed?Tonneson
yes - the request is https://Solley
Do you issue the request from an HTTPS page? If not, probably relevant: #1106434Mcgann
Does it help to change the timeout? Similar to: timeout: 4000, or some value you like :)Tonneson
request is from https; not cross domain or cross protocol.Solley
Please go through this bugs.jquery.com/ticket/6985Lonely
I had same problem in firefox, not sure but after making ajax call within setTimeout() function worked for me.Necrotomy
Have you figure it out? I have exactly same issue as yours, could you tell me your solution?Mouldy
H
14

Try only

async: false

in ajax option, I had the same problem.

Heptameter answered 9/11, 2012 at 12:47 Comment(0)
P
5

I would start by explicitly setting (and changing) some of the basic ajax options:

 cache: false,
 timeout: 60000,
 async: false
Prepare answered 2/11, 2012 at 14:3 Comment(2)
no impact. problem still persists. I'm thinking firefox can't parse large json strings under https. All speculation though.Solley
then try to reproduce the hypothesis in a isolated test-bed.Natividadnativism
W
4

What type of content your server returning. JSON or HTML content. Are you using charset=utf-8 in server content. Make sure your server response must be in JSON contentType. Another guess remove datatype: "html" from your code. Try for your luck.

If your server returns json means, try below

$.ajax({
            type: 'POST',
            url: '/Save',
            data: JSON.stringify(dataset),
            datatype: "json",
            contentType: "application/json",
            success: function (data, textStatus, jqXHR) {
                //alert("success");
            },
            error: function (jqXHR, textStatus, errorThrown) {
                //alert("error");
            }
        });

datatype: "json", contentType: "application/json" makes sense

Wraparound answered 8/11, 2012 at 19:27 Comment(2)
server response is html. On the request, the data posted is json.Solley
@FiveTools: on your html remove charset if you have and check.Wraparound
L
2

If you send this AJAX request from an event handler (example : click of a submit button), be sure to prevent the browser's default behavior (submitting the form), until you'll have 2 HTTP requests fired, with the first being aborted.

You can use e.preventDefault() to achieve this.

I just had this trouble on IE8.

Lema answered 13/11, 2012 at 14:17 Comment(0)
A
1

Check the maximum post size setting on your server.

Albumose answered 8/11, 2012 at 14:54 Comment(1)
we are logging server exceptions, and it doesn't even get that far. We have increased the request size for posts on the server, but has no impact on resolving this issue.Solley
B
1

I also had similar issues and tried some of the ideas described above. I finally fixed "aborted" state by :

  1. adding e.preventDefault(); and return false; to buttons event handlers
  2. adding datatype: "json", contentType: "application/json", to jQuery.ajax method params.

Thx to everyone for the clues.

Bicapsular answered 9/2, 2015 at 13:56 Comment(0)
C
0

This is either a cross domain issue or it is an issue with Firefox aborting your request because request is async. For cross domain you can check the origin of your request and what is allowed on webservice. You might have to read up on CORS.

If it is not cross domain then it is certainly a problem with request being async. Just change it to sync.

Cynthla answered 28/1, 2015 at 17:48 Comment(0)
S
0

If you are using 2-way SSL auth on a CORS request, Firefox will abort your jQuery ajax requests by default. This is due to differing implementations of CORS in Firefox and Chrome. You can resolve this issue in your client code by adding withCredentials: true to your XHR instances. In jQuery, you can add this to the ajax call:

xhrFields: {
  withCredentials: true
}

Check out these bug reports for more details:

I've also noticed that Firefox still absolutely refuses to send credentials on OPTIONS preflight requests, so you will need to configure your server to not require them (which seems crazy to me in a 2-way SSL scenario).

Scud answered 13/3, 2018 at 21:13 Comment(0)
R
0

ns_binding_aborted post request

During form submission if you are facing the issue of "ns_binding_aborted" then

You can use e.preventDefault() to fix this issue.

Runoff answered 24/7 at 8:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.