【发布时间】:2012-07-18 10:53:58
【问题描述】:
来自网络服务的输出,“http://localhost:6833/Service1.asmx/HelloWorld”:
<string xmlns="http://tempuri.org/">
[{"Name":"Pini","Age":"30","ID":"111"},{"Name":"Yaniv","Age":"31","ID":"Cohen"},{"Name":"Yoni","Age":"20","ID":"Biton"}]
</string>
HTML 代码:
<html>
<head>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "POST",
url: "Service1.asmx/HelloWorld",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert("Result: " + msg);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Error: " + textStatus);
}
});
});
</script>
</head>
<body>
</body>
</html>
当我在浏览器中运行 index.html 时,我收到错误警报。尝试了很多东西,但无法找出丢失的内容。
【问题讨论】:
-
只有错误:错误。但不确定该功能是如何工作的,这都是新的
-
试试这个警报(“错误:” + errorThrown);告诉我你得到了什么。
-
认为是的,尝试过:“localhost:6833/Service1.asmx/HelloWorld”和“Service1.asmx/HelloWorld”。第一个在我的浏览器中运行良好。
-
试试“~/Service1.asmx/HelloWorld”
-
由于路径有问题,请尝试“../../Service1.asmx/HelloWorld”或“/Service1.asmx/HelloWorld”或使用完整路径,您可以稍后将其更改为你的域名。
标签: c# javascript jquery web-services