gpt4 book ai didi

backbone.js - 获取主干模型时出错(在 Chrome 中有效,但在 Firefox 和 ie9 中无效)

转载 作者:行者123 更新时间:2023-12-03 05:02:55 25 4
gpt4 key购买 nike

我有一项服务可以在 Chrome 中返回正确的数据,但在 Firefox 和 ie9 中以错误结束。看起来 GET 返回了 200 OK 代码,但仍然以错误回调结束。我通过backbonejs获取数据(使用jquery.getJson和ajax我得到相同的结果)。如果我尝试从远程服务器或本地获取数据,也会得到相同的结果。

Chrome:版本 23.0.1271.64 mFF:16.0.2IE9:9.0.8112.16421

wcf:

[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/getData/{name}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
List<Names> getData(string name);

服务网址:

"http://serverABC:4000/myService.svc/getData/test"

从 javascript 获取:通过主干或 jqueryGetJson():

$.getJSON("http://serverABC:4000/myService.svc/getData/test", function () {
alert("success");
})
.success(function () { alert("second success"); })
.error(function (result) {
console.log('error:', result);
})

结果:“http://serverABC:4000/myService.svc/getData/test 200 OK 70ms”

标题:

Response Headers
Cache-Control private
Content-Length 6544
Content-Type application/json; charset=utf-8
Date Fri, 16 Nov 2012 14:09:46 GMT
Server Microsoft-IIS/7.5
Set-Cookie ASP.NET_SessionId=s3aguluzip0dw135glbxlwwf; path=/; HttpOnly
X-AspNet-Version 4.0.30319
X-Powered-By ASP.NET
Request Headers
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Connection keep-alive
Host svgwbip93:4000
Origin http://localhost:51280
Referer http://localhost:51280/Default.aspx?ReturnUrl=%2f
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0

调试结果:

readyState 0
responseText ""
status 0
**statusText "error"**
abort function()
always function()
complete function()
done function()
error function()
fail function()
getAllResponseHeaders function()
getResponseHeader function()
overrideMimeType function()
pipe function()
progress function()
promise function()
setRequestHeader function()
state function()
statusCode function()
success function()
then function()
toString function()

响应: - 为空(这很可能是问题所在(但正如我在 Chrome 中提到的,我得到了正确的 json 数据)

编辑1:我尝试使用 fiddler 获取原始响应,并且得到了 JSON。最大的问题是为什么回调会出错。这是我的原始回复:

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 29
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
Set-Cookie: ASP.NET_SessionId=kuv3g0r2dgmu5bpaoayj5lic; path=/; HttpOnly
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 16 Nov 2012 19:32:58 GMT

{"PlatformDrawingsResult":[]}

我验证了 json - 看起来没问题,那么可能是什么问题......嗯。我忘了提及我也在使用 requirejs (不确定这是否会带来一些启发,..)

干杯,米罗

最佳答案

解决方案是(感谢jwkeenan):

I put this line at the beggining of each method in my web service and now all browsers work.

HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); 

为了让它在 ie9 中工作,我需要将其添加到我的网络应用程序中:

$.support.cors = true;

关于backbone.js - 获取主干模型时出错(在 Chrome 中有效,但在 Firefox 和 ie9 中无效),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13418711/

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