1

As I am not able to find a way to set the content-type to JSON for the data I sent via XDomainRequest,

I naturally ask:

Is it IMPOSSIBLE to POST JSON with XDomainRequest?

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

4

3 回答 3

1

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

例如:如何使用 POST 方法在 XDR 中发送 JSON 数据

于 2013-02-27T13:58:49.627 回答
0

您仍然可以将 JSON 作为纯文本 POST 并让服务器端直接读取 POST 正文并进行处理,即使对于 IE 而言,缺少 Content-Type 也是如此。

于 2013-06-06T07:24:58.793 回答
0

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

您不能发送 content-type : application/jsonxdr。您甚至不能发送任何其他自定义标头。xdr 仅限于text/plain

你能做的最好的就是JSON.stringify()在服务器端使用和解析它。

xhr.send(JSON.stringify(jsonObject))
于 2015-11-05T11:56:31.913 回答