backbone.js 获取错误
我在 backbone.js 的 fetch 函数中获取响应时遇到问题。我将 Backbone.js 与 Rails 一起使用。
$(document).ready(function(){
window.projectPerformanceReport.fetch({
success: function(e) {
$("#loading").hide();
window.questionListView = new QuestionListView;
window.questionListView.render();
window.headerView = new HeaderView;
window.headerView.render();
},
error: function() {
alert("Error");
}
});
});
已经为 fetch 方法设置了一个 URL,并且它确实向返回 JSON 对象的在线服务器发出请求。我通过在新选项卡中独立点击该请求进行检查,效果很好。返回的 JSON 对象也是有效的。但是当我运行此页面时,我总是弹出“错误”?
任何帮助都会很棒。
谢谢
I am facing a problem with getting a response in fetch function of backbone.js. I am using Backbone.js with rails.
$(document).ready(function(){
window.projectPerformanceReport.fetch({
success: function(e) {
$("#loading").hide();
window.questionListView = new QuestionListView;
window.questionListView.render();
window.headerView = new HeaderView;
window.headerView.render();
},
error: function() {
alert("Error");
}
});
});
There is already a URL set for the fetch method and it does make a request to online server which returns a JSON object. I checked by hitting that request independently in new tab and it worked fine. Also the JSON object returned is valid. But when i run this page i always get popup of 'Error'?
Any help would be great.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,
我明白了问题是什么......发生的事情是,我调用以获取 JSON 对象的 Java_Servlet 以文本格式而不是 JSON 返回数据......(但它是有效的 JSON string)...在调用 ajax 方法时,我将类型设置为“json”,所以它失败了。
感谢所有阅读我的问题并思考解决方案的人。
但我观察到的一件奇怪的事情是,相同的代码在生产环境中运行,而不是在我的本地机器中运行???有谁知道为什么它会有这样的行为..???
谢谢:)现在我可以睡个好觉了!
Okay
I got what was the issue..... The thing that was happening was, The Java_Servlet which i was calling to get the JSON object was returning the data in text format instead of JSON... (But it was a valid JSON string)... and while calling the ajax method i had set the type as 'json' so it was failing.
Thanks to everyone who read my question and thought for a solution.
But one strange thing which i observed was, same code was working in production and not in my local machine??? Does anyone have some idea on why it could be behaving like that..???
Thanks :) Now i can sleep properly!!