我使用Knockout.js和Sammy.js编写了一个小型单页应用程序,并使用jQuery将数据发回服务器。
这在Firefox中运行良好,但我的所有POST都在IE中收到“400 Bad Request”响应。
我已经使用Fiddler查看发生了什么,唯一的区别是我可以看到IE包含Referer标头中的哈希值,但我不认为这会导致问题。
这是我的jQuery帖子:
$.ajax({
type: 'POST',
url: '/App_Presentation/BDM/RdmUserCategoryService.svc/GetUserCategoryUsersByCategory',
data: '{ "categoryId" : "' + this.params.catId + '" }',
contentType: 'application/json; charset=utf=8',
dataType: 'json',
success: function (data) {
self.editCategoryData({
CategoryID: ko.observable(categoryId),
CategoryName: ko.observable(categoryName),
UserList: ko.observableArray([])
});
self.editCategoryData().UserList(data.d);
}});
服务器上的方法没有被命中,成功回调也没有被命中。当我添加错误回调时,我得到的唯一信息是“错误请求”错误消息。
有没有人有任何想法?
答案 0 :(得分:1)
所以观看此内容的其他任何人都可以尝试解决此问题。尝试从charset
中删除contentType
。它适用于上述问题。
这可能与两个浏览器之间的轻微编码差异有关,因为请求的编码实际上与contentType
中指定的编码不匹配,WCF可能会拒绝传入的请求。虽然这不是一个肯定的火灾坚实的答案。这是我最好的。
最终守则:
$.ajax({
type: 'POST',
url: '/App_Presentation/BDM/RdmUserCategoryService.svc/GetUserCategoryUsersByCategory',
data: '{ "categoryId" : "' + this.params.catId + '" }',
contentType: 'application/json'
dataType: 'json',
success: function (data) {
self.editCategoryData({
CategoryID: ko.observable(categoryId),
CategoryName: ko.observable(categoryName),
UserList: ko.observableArray([])
});
self.editCategoryData().UserList(data.d);
}});