【问题标题】:IE8 XMLHttpRequest Send not WorkingIE8 XMLHttpRequest 发送不工作
【发布时间】:2014-05-22 16:32:12
【问题描述】:

我正在尝试使用 XMLHttpRequest 发送 POST 请求,但它不起作用..

我没有在 fiddler 看到任何对我的网址的调用..

IE开发者工具的控制台不显示任何错误..

我可以看到所有的警告框。

我还在 Internet 区域、Intranet 区域中启用了“跨域访问数据源”选项,并且我还将我的 localhost 添加到受信任的站点..

有人知道吗?

这是我的代码:

<!DOCTYPE html>
<html>
<head>

<script language="javascript" type="text/javascript">

function callService(id) {

    id.innerHTML = "Clicked!";
    alert("Antes do XMLHttpRequest!");
        var xmlhttp;
    try {
           xmlhttp = new XMLHttpRequest();
        } catch (ex) {
            xmlhttp = new window.ActiveXObject("Microsoft.XMLHTTP");
        }

    alert("Antes do url!");
    var url = "https://localhost:1234/blabla/blabla";

    alert("Antes do open!");


    xmlhttp.open("POST", url, true);

    alert("Antes do setRequestHeader!");
    xmlhttp.setRequestHeader("Content-type", "application/json");

    alert("Antes do onreadystatechange!");
    xmlhttp.onreadystatechange = function () { //Call a function when the state changes.
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            alert(xmlhttp.responseText);
        }
    }

    alert("Antes do parameters!");
    var parameters = JSON.stringify({"Values": {"Value": 2500,"ItemNumber": "1"},"PartnerID": "SUB","ProdCode": "CEC","Session": "321","OpCode": "10"});

    alert("Antes do send!");
    xmlhttp.send(parameters);
    alert("Depois do send!!");

}
</script>
<script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
</head>
<body>
<h1 onclick="callService(this)">Click on this text!</h1>
</body>
</html>

【问题讨论】:

    标签: json http post internet-explorer-8 request


    【解决方案1】:

    问题是我调用的链接错误。

    问题解决了;)

    【讨论】:

      猜你喜欢
      • 2014-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-01
      • 2013-06-09
      • 2011-04-09
      • 2011-10-26
      相关资源
      最近更新 更多