Domanda

I've written a small single-page application using Knockout.js and Sammy.js, plus jQuery for posting data back to the server.

This works fine in Firefox, but all my POSTs are getting a "400 Bad Request" response in IE.

I've used Fiddler to see what's going on, and the only difference I can see is that IE includes the hash in the Referer header, but I don't think that should cause a problem.

Here's my jQuery post:

$.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);
}});

The method on the server doesn't get hit, and the success callback doesn't get hit either. When I add an error callback, the only information I get is the "Bad Request" error message.

Has anyone got any ideas?

È stato utile?

Soluzione

So anyone else viewing this may try a solution to this problem. Try removing charset from your contentType. It worked for the problem above.

It could have to do with slight encoding differences between the two browsers, WCF may reject the incoming request given the encoding of the request doesn't actually match the encoding specified in the contentType. While this isn't a sure fire solid answer. It's the best I have.

Final Code:

$.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);
}});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top