我正在尝试使用XMLHttpRequest发送POST请求,但它无法正常工作..
我不会在小提琴手上看到我的网址。
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>
答案 0 :(得分:0)
问题是我正在调用的错误链接。
问题解决了;)