0
我创建了一个简单的selfhost用C#,其中:JSON输出与selfhost C#和阅读用JavaScript响应
public JObject Get()
{
jsonOut = @"{""server"": ""10.0.0.1"" }";
return JObject.parse(jsonOut);
}
当我尝试打开一个URL http://localhost:2000/api/test到Web浏览器,看到正确响应JSON:{“服务器“:”10.0.0.1“}。 之后我创建了一个网页:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdlocalhost">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
<meta name="description" content="Portale per Webmaster">
<meta name="keywords" content="HTML,CSS,JavaScript,PHP,ASP">
<meta http-equiv="refresh" content="900">
<script type="text/JavaScript">
function ajaxRequest() {
var xmlhttp = new XMLHttpRequest();
var url = "http://10.1.3.62:2000/api/test";
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var json=eval("("+xmlhttp.responseText+")");
document.getElementById("info").innerHTML = json.server;
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
window.onLoad = ajaxRequest();
setInterval(ajaxRequest, 2000);
</script>
</head>
<body>
<div id="info"></div>
</body>
</html>
,但我看不出有什么变化和开发工具在Firefox收到以下错误:
语法错误:JSON.parse:在行数据意外结束1列1的JSON数据
为什么不工作?
感谢