使用XDomainRequest POST JSON是不可能的吗?

时间:2013-02-27 13:56:02

标签: ajax internet-explorer post xdomainrequest

由于我无法找到通过XDomainRequest发送的数据的内容类型为JSON的方法,

我自然会问:

使用XDomainRequest发布JSON是不可能的吗?

Only text/plain is supported for the request's Content-Type header

3 个答案:

答案 0 :(得分:1)

看看其他一些问题,我想说这是可能的。

例如:How to send JSON data in XDR using the POST method

答案 1 :(得分:0)

你仍然可以将JSON作为纯文本发布,并让服务器端直接读取POST主体并处理它,甚至因为IE病毒而缺少Content-Type。

答案 2 :(得分:0)

根据http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx

您无法在xdr中发送content-type : application/json。您甚至无法发送任何其他自定义标头。 xdr仅限于text/plain

您可以做的最好的事情是使用JSON.stringify()并在服务器端解析它。

xhr.send(JSON.stringify(jsonObject))