我正在尝试在启动 Metro UI 应用程序之前返回 json 数据以使用它。我的网络服务不返回 json 数据,但它总是返回 xml 数据。有人可以帮助我吗?
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld() {
return "Hello World";
}
网页
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
var req = new XMLHttpRequest();
xmlhttp.setRequestHeader("Content-Type", "application/json");
function Roll() {
if (req.readyState == 4) {
alert(req.responseText);
alert("exiting");
}
}
function Test() {
alert("starting");
req.open("POST", "http://localhost:58718/testService/Service.asmx/HelloWorld", true);
req.onreadystatechange = Roll;
req.send(null);
}
</script>
</head>
<body>
<button onclick="javascript:Test()">TEST</button>
</body>
</html>