gpt4 book ai didi

jquery - 为什么我收到 OPTIONS 请求而不是 GET 请求?

转载 作者:行者123 更新时间:2023-11-28 05:52:56 33 4
gpt4 key购买 nike

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script>
$.get("http://example.com/", function(data) {
alert(data);
});
</script>

它向该 URL 发出 OPTIONS 请求,然后回调函数永远不会被调用。

当它不是跨域时,它工作正常。

jQuery 不应该只用 <script> 进行调用吗?节点然后在加载时执行回调?我知道我将无法获得结果(因为它是跨域的),但是没关系;我只是希望通话能够接通。这是一个错误,还是我做错了什么?

最佳答案

根据MDN ,

Preflighted requests

Unlike simple requests (discussed above), "preflighted" requests first send an HTTP OPTIONS request header to the resource on the other domain, in order to determine whether the actual request is safe to send. Cross-site requests are preflighted like this since they may have implications to user data. In particular, a request is preflighted if:

  • It uses methods other than GET or POST. Also, if POST is used to send request data with a Content-Type other than application/x-www-form-urlencoded, multipart/form-data, or text/plain, e.g. if the POST request sends an XML payload to the server using application/xml or text/xml, then the request is preflighted.
  • It sets custom headers in the request (e.g. the request uses a header such as X-PINGOTHER)

关于jquery - 为什么我收到 OPTIONS 请求而不是 GET 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37940877/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com