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

6
  • Only Error: error. But not sure how that function works, all new to this Commented Jul 18, 2012 at 11:18
  • Try this alert("Error: " + errorThrown); and tell me what you are getting. Commented Jul 18, 2012 at 11:20
  • Think so yes, tried: "localhost:6833/Service1.asmx/HelloWorld" and just "Service1.asmx/HelloWorld". The first one works fine in my browser. Commented Jul 18, 2012 at 11:25
  • try "~/Service1.asmx/HelloWorld" Commented Jul 18, 2012 at 11:26
  • Since the problem is with path, try "../../Service1.asmx/HelloWorld" or "/Service1.asmx/HelloWorld" or use the full path, you can latter change it to your domain name. Commented Jul 18, 2012 at 11:34

2 Answers 2

1

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

EDIT:

check this post for more information.

Sign up to request clarification or add additional context in comments.

Comments

0

Try adding this before your method.

 [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 

below

 [WebMethod]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.