相关疑难解决方法(0)

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

<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>
Run Code Online (Sandbox Code Playgroud)

它对该URL执行OPTIONS请求,然后从不使用任何内容调用回调.

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

不应该只是jQuery与一个<script>节点进行调用,然后在加载时进行回调吗?我明白我无法得到结果(因为它是跨域的),但那没关系; 我只是希望电话通过.这是一个错误,还是我做错了什么?

jquery xmlhttprequest http-get http-options-method

278
推荐指数
3
解决办法
32万
查看次数

如何在ASP.NET MVC/WebAPI应用程序中支持HTTP OPTIONS动词

我已经设置了一个ASP.NET Web应用程序,从MVC 4/Web API模板开始.看起来好像工作得很好 - 我没有发现任何问题.我使用Chrome和Firefox浏览网站.我已经使用Fiddler进行了测试,所有的回复似乎都在钱上.

所以现在我继续编写一个简单的Test.aspx来使用这个新的Web API.脚本的相关部分:

<script type="text/javascript">
    $(function () {

        $.ajax({
            url: "http://mywebapidomain.com/api/user",
            type: "GET",
            contentType: "json",
            success: function (data) {

                $.each(data, function (index, item) {

                    ....

                    });
                }
                );

            },
            failure: function (result) {
                alert(result.d);
            },

            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("An error occurred, please try again. " + textStatus);
            }

        });

    });
</script>
Run Code Online (Sandbox Code Playgroud)

这会生成一个REQUEST标头:

OPTIONS http://host.mywebapidomain.com/api/user HTTP/1.1
Host: host.mywebapidomain.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, …
Run Code Online (Sandbox Code Playgroud)

asp.net ajax asp.net-web-api

77
推荐指数
6
解决办法
11万
查看次数

与PrototypeJS共享原始资源

我在使用跨源资源共享和原型时遇到了一些麻烦.我对外部资源有简单的发布请求,对于简单的发布请求,必须满足一些规则:

Content-Type必须是application/x-www-form-urlencoded,multipart/form-data或text/plain,一个简单的请求不会使用http Request设置自定义标头,并且Server必须设置Access- Control-Allow-Origin标头正确.

使用vanilla JavaScript XMLHttpRequest一切正常,但是使用PrototypeJS它将无法工作,因为它接缝Prototype设置了一些自定义标头,我不知道如何防止它.

我通过以下方式在Prototype中尝试过:

new Ajax.Request('some.foreign-host.com/res.php', {
  method: 'post',
  postBody: 'foo=bar', 
  contentType: 'application/x-www-form-urlencoded', 
  onSuccess: function(e){
    // some custom code
  }
});
Run Code Online (Sandbox Code Playgroud)

知道如何让Prototype发送这么简单的CORS请求吗?


我有一个简单的JavaScript XMLHttpRequest创建的Headers的转储:

POST /bthesis/returnJSON.php HTTP/1.1    
Host: foreign-host.com                         
Connection: keep-alive                   
Referer: this-host.com
Content-Length: 9                        
Origin: this-host.com     
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: */*                              
User-Agent: [...]
Accept-Encoding: gzip,deflate,sdch       
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Run Code Online (Sandbox Code Playgroud)

原型请求创建的标题:

OPTIONS /bthesis/returnJSON.php HTTP/1.1 
Host: foreign-host.com                        
Connection: keep-alive                   
Referer: this-host.com
Access-Control-Request-Method: POST      
Origin: this-host.com      
Access-Control-Request-Headers: X-Prototype-Version, X-Requested-With, Content-type, Accept
Accept: */*                              
User-Agent: …
Run Code Online (Sandbox Code Playgroud)

javascript ajax.request prototypejs cors

5
推荐指数
2
解决办法
1万
查看次数

当浏览器说http请求被中止时,实际上发生了什么?

在某些情况下,浏览器可能会终止http请求。使用Firebug或状态列中通常可以说的内容,例如200 OK,它表示“已中止”(红色)。在Internet Explorer中发生这种情况时,用户可能会看到IE生成的消息“ Internet Explorer无法显示此页面”。

这里发生了什么?

我不认为这是超时问题,因为它发生的时间很短,我相信当响应时间更长时,我可以得到成功的响应(例如200)。

而且与服务器无关。该请求被浏览器中止。这并不是说我们有一个服务器错误。(例如500)。

也; 通常,相同的请求(使用相同的方法向相同的URL发送)。因此,对于SSL配置错误,这没什么好说的。

我假设这与Internet连接有关。但是我对网络/互联网了解不足,无法真正理解这是什么意思。

所以。具体问题是;什么情况下可能导致此错误?

browser http

5
推荐指数
2
解决办法
1万
查看次数