julio
julio

Reputation: 6728

Ajax GET request turning into OPTION request

I'm experiencing a weird behavior with an ajax request on a godaddy shared linux server. The request works perfectly on many other servers I've tested it on, but on this one, the GET request turns into an OPTIONS request for some reason.

Here's the js code (using mootools 1.1):

var a = new Ajax(myurl,{
            method: 'get',
            onComplete: function( response ){
                $('my_div').style.display="none";
                output_display( response );
            }
        });
        a.request();

You can see that the method is defined as GET. Yet when I watch the request happen with Firebug, it gets passed as an OPTIONS request. Any thoughts on how or why this would happen?

Upvotes: 2

Views: 1472

Answers (1)

Dimitar Christoff
Dimitar Christoff

Reputation: 26165

usually, there are two reasons for this sort of behaviour during XHR (ajax) requests.

  1. protocol bridging (from https to http or vice versa) whereby request url protocol differs to requested url
  2. subdomain difference (eg, domain.com requests from www.domain.com)

bottom line: for XHR to work, protocol and hostnames need to match due to access control restrictions.

reads:

http://www.w3.org/TR/access-control/#cross-origin-request-with-preflight0

ways around cross-domain policy restrictions: http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/

etc etc.

Upvotes: 2

Related Questions