AJAX https POST requests using jquery fail in Firefox
Asked Answered
S

5

3

I have a simple list of records in an HTML table with a delete link for each row. The delete link shoots off an AJAX post request to a fixed url that looks like: "/delete/record/5"

The AJAX request is created using jquery's .ajax() call with a POST message when running on a server that uses https. This call fails in Firefox 3 on OSX/Windows architectures. It works on all other browsers I've tested (OSX/Windows: Chrome, Safari, IE7.)

The requests are coming from an https site and going to the same https site. But I think somewhere during the process the original request starts off as http and there is a redirect attempt on our server to send it from http->https and Firefox rejects that redirect as some type of forgery.

Has anyone had experience doing .ajax() JQuery calls on an https site with Firefox? I notice something odd where if the request has "?var=xxx" arguments in the URL, the request seems to work more often then if it does not have those variables.

Stagnate answered 27/2, 2009 at 23:25 Comment(0)
S
12

Sounds like you're getting an HTTP 411 error.. This error can happen if you're sending a POST request without any data.

To fix this, add an empty object ({}) to the data property to your requests:

$.ajax({ 
    url: url, 
    type: 'POST', 
    data: {}, // <- set empty data 
    success: function(data, textStatus) { 
        // do something 
    } 
}); 
Scrap answered 28/2, 2009 at 3:18 Comment(2)
Thanks for the help! This was exactly the problem! I had FF3 and nginx, putting in a blank data{} fixes the problem. I don't need the id in the data{} for delete because the id is already in the url. Spot on advice! Thanks.Stagnate
Fixed a problem I was having where Firefox 3.0.x would fail on an ajax call. Thanks.Find
N
1

That seems unlikely... not that I'm doubting you. But I would suggest downloading Wireshark and watching your HTTP traffic to see if you can't isolate the problem. You'll be able to compare the request sent by other browsers against the request sent out by FF3 and see what sort of response is coming back. If it is indeed a problem with jQuery not functioning correctly in FF3 you might be able to alter some of the code to work properly.

Noelianoell answered 27/2, 2009 at 23:42 Comment(0)
E
1

You can probably install the Firefox Live Headers extension that will give you access to all the information in your requests/responses. This way you'll be catch any differences.

Expertism answered 27/2, 2009 at 23:47 Comment(0)
D
0

Do you have any plugins or GreaseMonkey scripts installed on your Firefox?

I have never had issues with jQuery AJAX requests on HTTPS. I'd suggest taking a look at what Firebug turns up if you haven't already.

Dorise answered 28/2, 2009 at 0:35 Comment(0)
S
0

I got $.post to work in Firefox by sending an empty object as the data parameter. Notice the empty brackets for parameter 2:

$.post(url, {}, function(response){ alert('done'); }, "json");
Shaffert answered 27/3, 2009 at 21:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.