Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery: why $.get send OPTION packet?

Tags:

jquery

ajax

$.get('http://localhost/a.bb?cmd=<abc></abc>', function(data) {
   alert('result comes back.');
   $('.result').html(data);
  });
);

Above is the code I want send to server, why jquery send OPTION for me? I want GET method.

Thanks.

like image 254
Bin Chen Avatar asked May 23 '26 21:05

Bin Chen


2 Answers

jQuery/webbrowser will send a HTTP OPTIONS request whenever the URL concerns a different domain than the one from which the inital page is been requested and the jQuery dataType is not JSONP. On an OPTIONS request, the server should return an Allow header with all HTTP methods which are allowed to be used. E.g. GET,POST. The webbrowser will then continue the actual XMLHttpRequest.

This all is in the name of Same Origin Policy.

like image 66
BalusC Avatar answered May 26 '26 13:05

BalusC


this probably coming from your browser, or the way you format your get request it my be safer to pass the data as

$.get('http://localhost/a.bb',{"cmd":"<abc></abc>"}, function(data) {
        alert('result comes back.');
        $('.result').html(data);
    });
);
like image 36
dvhh Avatar answered May 26 '26 11:05

dvhh