简体   繁体   English

jQuery和C#Web服务问题

[英]Problems with jquery and C# web service

Output from web service, "http://localhost:6833/Service1.asmx/HelloWorld": Web服务“ 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 code: 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>

When i run index.html in browser i get the Error alert.. Tried alot of things, but cant find out whats missing.. 当我在浏览器中运行index.html时,我收到错误警报。尝试了很多事情,但找不到丢失的内容。

your json in encapsulated in a xml string, i guess thats your problem. 您的json封装在xml字符串中,我想这就是您的问题。

EDIT: 编辑:

check this post for more information. 查看帖子以获取更多信息。

Try adding this before your method. 尝试在方法之前添加它。

 [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 

below 下面

 [WebMethod]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM