以下代码在IE7中无法正常工作,原因是什么?
var http = new XMLHttpRequest();
var url = 'http://my_site.com/';
var obj = createJsonParamsObj();
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send(JSON.stringify(obj));
从文档上看,new XMLHttpRequest()
应该会起作用,但我有些疑虑,因为我无法测试它(只能在兼容模式下),所以也许最好使用new ActiveXObject
。
json2.js
吗?据我记得,IE 7(也许还有 IE 8)没有原生的JSON.stringify
函数,因此我们需要包含json2.js
(可以在这里下载:https://github.com/douglascrockford/JSON-js),以便使用JSON
对象和其方法。 - Fernando Jorge Mota