jQuery ajax POST data is empty on the server for some clients

混江龙づ霸主 提交于 2019-12-11 17:50:58

问题


I encountered a very peculiar problem and none of the answers I found here solves it.

On SOME clients (IE7, IE8) when I post the data using jQuery Ajax, such as:

$.ajax({
    type: 'POST',
    url: '<%= ResolveUrl"~/User.svc/GetUserListForCity") %>',
    data: '{"city":' + cityId + '}',
    contentType: 'application/json; charset=UTF-8',
    dataType: 'json',
    success: processList,
    error: showErrorAlert
});

The error I am getting:

"The OperationFormatter could not deserialize any information from the Message because the Message is empty (IsEmpty = true)."

However when I attempt to use Fiddler to look at the data, the request is successful.

The server is IIS and the request is served by WCF Web Service (webHttpBinding). Removing contentType to allow defaults is being rejected by the server as it expects JSON. Any suggestions are very appreciated.


回答1:


Try this.. look's like you are sending data object is wrong

data: {"city": cityId }, // If cityID is a string this should do

OR

data: '{"city":"' + cityId + '"}',

There might also be a problem with the way you are sending the url.. Try using a absolute path and check if that works..



来源:https://stackoverflow.com/questions/12607500/jquery-ajax-post-data-is-empty-on-the-server-for-some-clients

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!