views:

38

answers:

1

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?

+1  A: 

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.

Dimitar Christoff