热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

jQuery:我得到OPTIONS请求而不是GET-jQuery:IgetOPTIONSrequestinsteadofGET

IamusingsimplejQuery我使用的是简单的jQuery$.get(.);HereinsteadofgettingGETresponseIget

I am using simple jQuery

我使用的是简单的jQuery

$.get( .... );

Here instead of getting GET response I get OPTIONS.( checked in firebug Net)

这里没有获得GET响应而是获得OPTIONS。(在firebug Net中检查)

Same code is working fine in Safari. Looks like some problem with Firefox.

相同的代码在Safari中正常工作。看起来像Firefox的一些问题。

Any workaround / solutions to fix this problem..

解决此问题的任何解决方法/解决方案..

Thanks

Kurund

5 个解决方案

#1


27  

The OPTIONS request what you see is the preflight request, you can read about that here:

OPTIONS请求你看到的是预检请求,你可以在这里阅读:

  • https://developer.mozilla.org/En/HTTP_access_control
  • http://www.w3.org/TR/cors/
  • http://msdn.microsoft.com/en-us/library/cc288060(VS.85).aspx

It's there because you're requesting a cross-domain XMLHttpRequest so the browser has to check whether your request is allowed on the remote server or not.

它就在那里,因为您正在请求跨域XMLHttpRequest,因此浏览器必须检查您的请求是否在远程服务器上被允许。

There are two solutions to solve the problem (as mentioned above):

解决问题有两种解决方案(如上所述):

  • implement the response for the OPTIONS request with the corresponding Access-Control-* headers
  • 使用相应的Access-Control- *标头实现OPTIONS请求的响应

  • use a JSONP request instead of simple JSON
  • 使用JSONP请求而不是简单的JSON

#2


1  

This is likely due to restrictions on Javascript doing cross-domain XMLHttpRequests. This is generally not allowed for security reasons. See the question referenced above, or a similar question I asked.

这可能是由于Javascript执行跨域XMLHttpRequests的限制。出于安全原因,通常不允许这样做。请参阅上面提到的问题或我提出的类似问题。

To solve this problem:

要解决这个问题:

  • Write a sever side component (using PHP or whatever) that will retrieve the remote resource on behalf of your AJAX request, or
  • 编写将代表您的AJAX请求检索远程资源的服务器端组件(使用PHP或其他),或

  • Do a JSONP call: see http://www.insideria.com/2009/03/what-in-the-heck-is-jsonp-and.html (or hunt around StackOverflow for JSONP) :)
  • 做一个JSONP调用:请参阅http://www.insideria.com/2009/03/what-in-the-heck-is-jsonp-and.html(或者围绕StackOverflow寻找JSONP):)

Hope that helps!

希望有所帮助!

#3


1  

I had the same issue, the cause I figured was in the html section I had set the base element to this

我有同样的问题,我想到的原因是在html 部分我已经设置了基本元素


Which I changed to

我改成了


#4


0  

I hope this helps someone: http://kurund.com/blog/2010/09/09/how-to-call-external-site-url-using-jquery-ajax/

我希望这有助于某人:http://kurund.com/blog/2010/09/09/how-to-call-external-site-url-using-jquery-ajax/

#5


0  

You are sending request to cross domain.

您正在向跨域发送请求。

For cross-domain requests, setting the content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or text/plain will trigger the browser to send a preflight OPTIONS request to the server.

对于跨域请求,将内容类型设置为application / x-www-form-urlencoded,multipart / form-data或text / plain以外的任何内容将触发浏览器向服务器发送预检OPTIONS请求。

So you may need change specify contentType to avoid OPTION request. Example:-

因此,您可能需要更改指定contentType以避免OPTION请求。例:-

$.ajax({
    url: "crossdomainurl",
    type: "GET",
    contentType: 'text/plain'
}); 

推荐阅读
author-avatar
jianji
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有