- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一项服务可以在 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/
我开发了一个 jquery &backbone.js 网络应用程序。 一个组件有一个 html 表,该表后面是一个主干.js 集合。 此集合中的任何更改都应该导致 html 表的更新,所以我写 thi
我创建了一个由 HTTP Basic 保护的无状态 RESTful API。 在客户端,我将创建一个登录表单,向/auth-check 发送请求以检查凭据,并根据状态代码,将这些凭据存储在客户端并使用
我已经有一个具有经典结构的存储库 /branches /current /beta /tags /1.0 /2.0 /trunk 我想从当前的编辑器切换到 Eclipse,但我应该创建
我正在阅读 red bean SVN book ,它说要像这样布局主干、分支和标签文件夹: $ svn list file:///var/svn/multi-project-repo project-
当特定属性发生变化时,Backbone 模型触发自定义事件的好方法是什么? 到目前为止,这是我得到的最好的: var model = Backbone.Model.extend({ initi
我想避免在 Backbone.Collection 上的每个“添加删除重置”事件上重新渲染。 所以在 Backbone.View 中我可能有: this.listenTo(this.collectio
这一定是我没有正确理解的东西。 我有一个名为 Album 的 Backbone 模型: var Album = Backbone.Model.extend({ idAttribute: "_id",
假设我有一个具有一堆 bool 属性的 Backbone 模型: Car = Backbone.Model.extend({}); car_one = new Car({ a_c: true,
我从 collection.fetch() 调用中得到一个包含多个嵌套对象的对象。有没有办法解析这些子对象并将它们作为单独的模型传递到集合中? 这是我要返回的数据的示例。从服务器获取时,我想将它作为
有一个脚本(js),我希望在它上面运行,比如$(document).ready()。有一种方法可以在模板(例如 home_tpl.html)文件中编写脚本。但我确信这不是一个好方法。 我正在从主干 V
配合我正在尝试从主干集合中包含的所有模型中获取更大的属性。 举个例子: App.Models.Example = Backbone.Model.extend({ defaults: {
我遇到这样一种情况,我需要为一个人保存几个对象,但一次保存一个对象,并且在获取时,我将所有对象作为一个数组以及该人的信息。 这是模型的样子: //Model for one save { pe
我开始阅读一些 Backbone 教程,发现一件让我惊讶的事情。为什么模型是在 View 内部创建的?如果我想要一个模型有两个不同的 View (我认为 MVC 的用途)怎么办?假设我需要一个模型 C
我使用backbone.js 创建了一个小型网站。它托管在 IIS 7 中。 路由: routes: { "/": "index", "": "ind
我现在正在构建一个 View ,当我单击 .organization 链接时,我想触发我的编辑事件,但是单击此元素时,没有任何内容被触发,我无法理解为什么。 这是构建我的 View 的代码, App.
我有一些全局参数,我想在每次调用集合上的提取时发送这些参数...我的问题是我不想声明 data: { ... }每次我获取。 有没有一种方法可以在 Collection 本身内部提供默认参数,并可以添
Backbone 新手在这里。我想开始在 Web 应用程序上使用主干(后端是 Ruby on Rails),直到现在它的客户端功能还很少(一些用于执行 slideToggles 的 jquery,以及
我想知道是否有办法从其中一个模型中获取对集合的引用。例如,如果下面集合中的任何人以某种方式知道属于一个集合或多个集合。 Fiddle (function() { window.App = {
如何在集合获取中阻止模型的解析功能? $(function() { var Task = Backbone.Model.extend({ url : function(
我们一直在使用位于文件夹根目录中的存储库,一切都很好。然而,自从网站上线后,我们需要对一些工作进行分支,但由于缺少主干而无法这样做。 我的问题是,如何在当前目录结构中创建一个主干并将所有当前内容移动到
我是一名优秀的程序员,十分优秀!