0

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..

stianboe
  • 441
  • 3
  • 7
  • 20

2 Answers2

1

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

EDIT:

check this post for more information.

Community
  • 1
  • 1
randoms
  • 2,793
  • 1
  • 31
  • 48
0

Try adding this before your method.

 [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 

below

 [WebMethod]
Ashwin Singh
  • 7,197
  • 4
  • 36
  • 55