jquery GET或POST被触发为具有空白响应的OPTION

时间:2012-02-01 13:18:12

标签: jquery

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
       alert("jquery loaded");
       $.get('country.php?id=117',function(d){
               alert('something');
       });
})
</script>

代码很简单,“jquery loaded”警报就可以了。另外正如您所看到的,我请求的页面位于同一服务器和域上,因此不应该有任何跨浏览器问题。 country.php simple会回显“hello world”,如果我在浏览器中访问该页面,它会毫不费力地显示。

但是当我尝试运行get方法时(我也尝试使用POST),没有任何反应。 Firebug将请求显示为OPTIONS而不是GET,并显示空白的html响应。对于我尝试过的每个网址以及所有浏览器中的任何想法都会发生这种情况吗?

顺便说一句,这是firebug标题日志:

Response Headers
Connection  Keep-Alive
Content-Type    text/html
Date    Wed, 01 Feb 2012 13:04:56 GMT
Keep-Alive  timeout=5, max=75
Server  Apache
Transfer-Encoding   chunked
____________________________________________________________________________

Request Headers
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Access-Control-Request-He...    x-requested-with
Access-Control-Request-Me...    GET
Connection  keep-alive
Host    shikenan.com
Origin  https://shikenan.com
User-Agent  Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1 FirePHP/0.6
x-insight   activate

2 个答案:

答案 0 :(得分:0)

我知道你说它是同域的,但OPTIONS部分的确暗示了跨域。您的HTML文件中是否有<BASE>标记?

See also this SO question

答案 1 :(得分:0)

试试这个

$(function(){
   $.ajax({
      url: "country.php",
      data: {id: 117},
      success: function(data){
      alert("something")
   }
  });
});