Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery POST request transforming into OPTIONS. Why?

I explicitly specify a POST and I don't see the post data in the Request and more over specifies it has a OPTIONS.

The response should be a HTML specifying matching users to Query in table format. I am trying to post and read the html to create a auto-complete input box.

This the Jquery Code:

$.post('https://internal.company.com/data/displayUserList',
    { Email: "", Name: "%GEORGE%"}, 
    function(responseText, textStatus) {
        console.log("Response:\n" + responseText + textStatus)
    }
);

Request captured by FireBug1.6.1 (Firefox)

OPTIONS /data/displayUserList HTTP/1.1
Host: internal.company.com
User-Agent: Mozilla/5.0 Firefox/3.6.8
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Origin: null
Access-Control-Request-Method: POST
like image 822
hashg Avatar asked Jan 11 '11 09:01

hashg


1 Answers

This could happen if you violate the same origin policy restriction. The Access-Control-Request-Method request header makes me think this is the case. I see that you specify a full address https://internal.company.com/data/displayUserList in your post request. Make sure that the page hosting this script is originating from https://internal.company.com as well. The best would be to use a relative address:

$.post('/data/displayUserList', { Email: "", Name: "%GEORGE%" }, 
    function(responseText, textStatus) {
        console.log("Response:\n" + responseText + textStatus);
    }
);
like image 52
Darin Dimitrov Avatar answered Oct 07 '22 00:10

Darin Dimitrov