1

I'm using jQuery 1.8.2 to call some backend server api's via jQuery's ajax POST. The backend server and the webpage are both on the same domain.

In my js file, I'm simply calling $.post('/createAccount',data,function(e) { alert(e); });

In Fiddler, this request is being sent as a GET, in IE9.

GET http://[redacted]/createAccount HTTP/1.1
Accept: */*
Origin: [redacted]
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: [redacted]
Connection: Keep-Alive
Pragma: no-cache

The same page using Chrome (latest) returns the following in Fiddler:

POST http://[redacted]/createAccount HTTP/1.1
Host: [redacted]
Connection: keep-alive
Content-Length: 103
Origin: http://[redacted]
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: */*
Referer: http://[redacted]/builder?token=[redacted]
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

email=test123&token=[redacted]&company=tokentest1

Here is the code using $.ajax instead of $.post (same issue):

        $.ajax({
            url : '/createAccount',
            type : 'POST',
            data : obj,
            dataType : 'json',
            cache: 'false',
            success : function(data) {
                if(data.status === 'ok') {

                } else {
                    alert('error');
                }
            }
        });
4
  • For debugging, can you switch to using $.ajax and compare the results?
    – Kevin B
    Oct 5, 2012 at 20:38
  • I can (actually the original call was $.ajax({...,type:'POST'}). Is there any special benefit wrt debugging?
    – Alan
    Oct 5, 2012 at 20:39
  • Well, since $.post forwards to $.ajax, it eliminates $.post as the cause.
    – Kevin B
    Oct 5, 2012 at 20:40
  • 1
    I'm not sure if it'll help, but what if you set contentType: 'application/json; charset=UTF-8'? Same result? Try removing the cache: 'false' as well.
    – kendaleiv
    Oct 5, 2012 at 21:21

1 Answer 1

0

This was a derp moment. I had some code else where that would fallback to MSFT's XDomainRequest, and in that code it was forcing all requests to get, instead of pulling the request type from the jQuery options object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.