tags:

views:

37

answers:

3
$.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.

+2  A: 

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.

BalusC
+1  A: 

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);
    });
);
dvhh
A: 

I'm not sure what you mean, but this seems to work fine:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
</head>
<body>

<xmp class="result"></xmp>

<script>
jQuery(document).ready(function($){

    /*$.ajax({
        url: 'http://localhost/stackoverflow/echo.php',
        data: {cmd: '<abc></abc>'},
        success: function(data) {
            $('.result').html(data);
        }
    });*/

    $.get('http://localhost/stackoverflow/echo.php?cmd=&lt;abc&gt;&lt;/abc&gt;', function(data) {
        $('.result').html(data);
    });

});
</script>

</body>
</html>

And the PHP file to simulate the answer:

<?php

echo "Received this from GET: " . $_GET['cmd'];

?>
wildpeaks