16

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
Kurund Jalmi
  • 1,285
  • 4
  • 19
  • 30

5 Answers5

28

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

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
KARASZI István
  • 30,900
  • 8
  • 101
  • 128
  • That seems to be my case. But how would I implement the response for the OPTION request? Where should I implement it? My WebMethod doesn't even get called. Do I need to override something? – Nawaz Sep 29 '12 at 21:30
  • @Nawaz: I'm not familiar with .NET but maybe this article could help you: http://encosia.com/using-cors-to-access-asp-net-services-across-domains/ – KARASZI István Sep 30 '12 at 16:24
  • 6
    I have to say the cross-domain behaviour of 'modern' browsers is getting ridiculous. If you have a server like couchdb which sends Access-Control-Allow-Origin: * but doesn't implement OPTIONS you can't do a simple AJAX GET because the browser decides to 'check' first and break everything. The developer knows the GET will work but the browser doesn't believe them! – Marc Oct 27 '12 at 21:18
1

This is likely due to restrictions on Javascript doing cross-domain XMLHttpRequests. This is generally not allowed for security reasons. See the question referenced above, or a similar question I asked.

To solve this problem:

Hope that helps!

Community
  • 1
  • 1
fitzgeraldsteele
  • 4,547
  • 3
  • 24
  • 25
1

I had the same issue, the cause I figured was in the html <head> section I had set the base element to this

<base href="http://local.develepment.url" />

Which I changed to

<base href="http://<?php echo $_SERVER['HTTP_HOST']?>/" />
Moak
  • 12,596
  • 27
  • 111
  • 166
0

I hope this helps someone: http://kurund.com/blog/2010/09/09/how-to-call-external-site-url-using-jquery-ajax/

Kurund Jalmi
  • 1,285
  • 4
  • 19
  • 30
0

You are sending request to cross domain.

For cross-domain requests, setting the content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or text/plain will trigger the browser to send a preflight OPTIONS request to the server.

So you may need change specify contentType to avoid OPTION request. Example:-

$.ajax({
    url: "crossdomainurl",
    type: "GET",
    contentType: 'text/plain'
}); 
Bala
  • 913
  • 9
  • 18