Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: I get OPTIONS request instead of GET

Tags:

jquery

I am using simple jQuery

$.get( .... );

Here instead of getting GET response I get OPTIONS.( checked in firebug Net)

Same code is working fine in Safari. Looks like some problem with Firefox.

Any workaround / solutions to fix this problem..

Thanks

Kurund

like image 363
Kurund Jalmi Avatar asked Nov 16 '09 18:11

Kurund Jalmi


People also ask

Why is an options request sent?

The OPTIONS request method is sent by browsers to find out the supported HTTP methods and other parameters supported for the target resource before sending the actual request. Browsers send OPTIONS requests when they send a CORS request to another origin.

Why is there an options request before post?

Prevent sending the post data, if it wont be processed This is the only reason what is valid. Using options request will prevent sending the post data to the server unnecessarily.

How do you request a get by method?

The GET method is used to retrieve information from the given server using a given URI. Requests using GET should only retrieve data and should have no other effect on the data. Same as GET, but transfers the status line and header section only.

What is options method for?

The HTTP OPTIONS method is used to request information about the communication options available for the target resource. The response may include an Allow header indicating allowed HTTP methods on the resource, or various Cross Origin Resource Sharing headers.


1 Answers

The OPTIONS request what you see is the preflight request, you can read about that here:

  • https://developer.mozilla.org/En/HTTP_access_control
  • http://www.w3.org/TR/cors/
  • http://msdn.microsoft.com/en-us/library/cc288060(VS.85).aspx

It's there because you're requesting a cross-domain XMLHttpRequest so the browser has to check whether your request is allowed on the remote server or not.

There are two solutions to solve the problem (as mentioned above):

  • implement the response for the OPTIONS request with the corresponding Access-Control-* headers
  • use a JSONP request instead of simple JSON
like image 124
KARASZI István Avatar answered Nov 09 '22 04:11

KARASZI István