jQuery ajax POST数据在某些客户端的服务器上是空的 [英] jQuery ajax POST data is empty on the server for some clients

查看:371
本文介绍了jQuery ajax POST数据在某些客户端的服务器上是空的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个非常特殊的问题,我在这里找到的答案都没有解决。

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

在我使用jQuery Ajax发布数据时,在某些客户端(IE7,IE8)上,例如:

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

我得到的错误:


OperationFormatter无法反序列化消息中的任何信息,因为消息为空(IsEmpty = true)。

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

但是,当我尝试使用Fiddler查看数据时,请求成功。

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

服务器是IIS,请求由WCF Web服务(webHttpBinding)提供。删除contentType以允许默认值被服务器拒绝,因为它需要JSON。
任何建议都非常感谢。

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.

推荐答案

试试看..就像你发送的数据对象错误

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

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

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..

这篇关于jQuery ajax POST数据在某些客户端的服务器上是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆