If I put the parameters in, I get no success/error/completed callbacks, but Fiddler shows a 200 response and my requested json data is there. That's the key. Fiddler is showing the round trip was a success and the requested data is here client side and in good order. Problem is backbone success/failure/completed not called. Just get a big nothing.
如果我输入参数,就不会得到成功/错误/完成的回调,但是Fiddler显示了200个响应,并且我请求的json数据也在那里。这是关键。Fiddler显示往返是成功的,所请求的数据在客户端,并且运行良好。问题是骨干成功/失败/未被调用。什么都没有。
With the exact same base URL, if I take the parameters out (and remove them from my web service in parallel), both success and completed are triggered. Below is my fetch "with" parameters:
使用相同的基本URL,如果我取出参数(并从web服务中并行地删除它们),成功和完成都会被触发。下面是我的fetch“with”参数:
myModel.fetch({
data: {
name: 'Bob',
userid: '1',
usertype: 'new'
}
}, {
success: (function () {
alert(' Service request success: ');
}),
error: (function (e) {
alert(' Service request failure: ' + e);
}),
complete: (function (e) {
alert(' Service request completed ');
})
});
How can the backbone behavior be different? It's the same URL, just with or without parameters.
骨干网的行为怎么会不同呢?它是相同的URL,有或没有参数。
I'm guessing the distinction is that under the hood in the backbone fetch, the "with" parameters scenario is a post and the "without" parameters is a simple get. The IE console reflects this with slightly different output.
我猜区别在于,在主干获取的引擎盖下,“with”参数场景是一个post,“without”参数是一个简单的get。IE控制台的输出略有不同。
"With" parameters my IE browser console reports a warning (not an error but a warning) that the request required CORS:
有了“参数,我的IE浏览器控制台报告一个警告(不是错误,而是警告),请求需要CORS:
!SEC7118: XMLHttpRequest for http://example.com/service/myservice.asmx/myoperation?name=Bob&userid=1&usertype=new required Cross Origin Resource Sharing (CORS).
为http://example.com/service/myservice.asmx/myoperation? ! SEC7118:XMLHttpRequest名称=Bob&userid=1&usertype=新的跨源资源共享(CORS)。
I think it's just telling me "hey, you made a cross origin request and I let it through". "Without" the parameters I don't get that warning. I do have the service headers set to:
我想它只是在告诉我“嘿,你提出了一个跨境申请,我让它通过了”。没有参数,我不会得到警告。我的服务标题设置为:
Access-Control-Allow-Origin: *
Access-Control-Allow-Origin:*
And the responses do indeed come back reflecting that policy.
人们的反应确实反映了这一政策。
So the question is why don't the backbone success/error/completed callbacks trigger "with" the parameters? The data makes it back. Shouldn't backbone reflect success?
所以问题是,为什么不使用“参数”来触发主干成功/错误/已完成的回调?数据又回来了。不应该骨干反映成功?
1 个解决方案
#1
14
Put your success
, error
, and complete
methods in the same object you have data
. There should only be the single object. Under the hood Backbone simply uses jQuery's ajax()
method so the object you pass to fetch()
can use any property that could be included in the settings object passed to $.ajax()
.
将您的成功、错误和完整方法放在您拥有的同一对象中。应该只有一个对象。在hood主干下,只需使用jQuery的ajax()方法,因此传递给fetch()的对象可以使用传递给$.ajax()的settings对象中包含的任何属性。
myModel.fetch({
data: {
name: 'Bob',
userid: '1',
usertype: 'new'
},
success: (function () {
alert(' Service request success: ');
}),
error: (function (e) {
alert(' Service request failure: ' + e);
}),
complete: (function (e) {
alert(' Service request completed ');
})
});
#1
14
Put your success
, error
, and complete
methods in the same object you have data
. There should only be the single object. Under the hood Backbone simply uses jQuery's ajax()
method so the object you pass to fetch()
can use any property that could be included in the settings object passed to $.ajax()
.
将您的成功、错误和完整方法放在您拥有的同一对象中。应该只有一个对象。在hood主干下,只需使用jQuery的ajax()方法,因此传递给fetch()的对象可以使用传递给$.ajax()的settings对象中包含的任何属性。
myModel.fetch({
data: {
name: 'Bob',
userid: '1',
usertype: 'new'
},
success: (function () {
alert(' Service request success: ');
}),
error: (function (e) {
alert(' Service request failure: ' + e);
}),
complete: (function (e) {
alert(' Service request completed ');
})
});