【问题标题】:jQuery ajax POST data is empty on the server for some clients对于某些客户端,jQuery ajax POST 数据在服务器上为空
【发布时间】:2012-09-26 17:48:59
【问题描述】:

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

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

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

我得到的错误:

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

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

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

【问题讨论】:

  • 我把javascript代码的格式弄乱了,很抱歉。

标签: javascript jquery ajax http-post


【解决方案1】:

试试这个..看起来你发送的数据对象是错误的

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

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

您发送 url 的方式也可能有问题。尝试使用绝对路径并检查是否可行。

【讨论】:

  • 该代码适用于大多数客户端,因此必须正确。我忘了添加该请求来自内联框架。会不会是个问题?
猜你喜欢
  • 2016-10-05
  • 1970-01-01
  • 2020-04-27
  • 2013-11-12
  • 2015-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多