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.

FiveTools
  • 5,970
  • 15
  • 62
  • 84

8 Answers8

12

Try only

async: false

in ajax option, I had the same problem.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Marys
  • 139
  • 4
5

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

 cache: false,
 timeout: 60000,
 async: false
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

Gowri
  • 16,587
  • 26
  • 100
  • 160
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.

Vince
  • 3,274
  • 2
  • 26
  • 28
1

Check the maximum post size setting on your server.

Bradley Thomas
  • 4,060
  • 6
  • 33
  • 55
  • 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. – FiveTools Nov 09 '12 at 02:21
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.

dunpeal69
  • 121
  • 2
  • 6
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.

Tayyab Ali
  • 91
  • 1
  • 1
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).

heez
  • 2,029
  • 3
  • 27
  • 39