stianboe
stianboe

Reputation: 441

Problems with jquery and C# web service

Output from web service, "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>
<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..

Upvotes: 0

Views: 122

Answers (2)

randoms
randoms

Reputation: 2783

your json in encapsulated in a xml string, i guess thats your problem.

EDIT:

check this post for more information.

Upvotes: 1

Ashwin Singh
Ashwin Singh

Reputation: 7355

Try adding this before your method.

 [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 

below

 [WebMethod]

Upvotes: 0

Related Questions