我创建了一个WCF REST服务,它只返回一个像这样的JSON {“Id”:10,“Name”:“Peter”}并使用Chrome我可以看到这个响应,但使用以下HTML5,状态如下:有谁能告诉我我做错了什么?感谢
<!DOCTYPE html>
<html>
<head>
<title>Company Name</title>
<link rel="shortcut icon" href="favicon.ico"/>
<script>
window.onload = function()
{
var url = "http://localhost:8732/DataService/data/10";
request = new XMLHttpRequest();
request.onreadystatechange = function()
{
if(request.readyState == 4)
{
if(request.status == 404)
{
document.getElementById("content").innerHTML = "No page found";
}
if(request.status == 2 || request.status == 200)
{
document.getElementById("content").innerHTML = "<br /><br /><br />Response: " + request.responseText;
}
else
{
document.getElementById("content").innerHTML = "Status: " + request.status +" ReadyState: " + request.readyState + "<br /> " + request.responseText;
}
}
}
request.open("GET", url, true);
request.send(null);
}
</script>
</head>
<body>
<div id="container" style="width:100%;">
<div id="header" style="position:absolute; height:100px;width:inherit;">
<img src="Dialog.bmp" alt="Missing" />
</div>
<!-- <div id="menu" style="background-color:#33CCFF; height:200px;width:100px;float:left;">
<b>Menu</b><br>
HTML<br>
CSS<br>
JavaScript</div> margin:0 auto; height:100%;width:100%;-->
<br /><br /><br /><br />
<div id="content" style="background-color:#333333; height:500px;width:inherit;float:left; color:white">Content goes here</div>
<div id="footer" style="background-color:#00A8FF;clear:both;text-align:center;color:white;font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif">Copyright © CompanyName</div>
</div>
</body>
</html>
答案 0 :(得分:0)
好像我在做跨域请求,IE + 9允许它,但不是Chrome。
我现在已将JSON WCF请求移动到Apache转发的PHP cURL。