Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Web Service code... Service.asmx

C#
[WebMethod]
   public string HelloWorld() {
       string log = "Hello World";
       JavaScriptSerializer jss = new JavaScriptSerializer();
       string json = jss.Serialize(log);
       return json;
   }




where I want to get web service data... through ajax.

XML
<script type="text/javascript" src="

http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script type="text/javascript">
     $(document).ready(function(){

            $.ajax({
                type: "POST",
                url: "Service.asmx/HelloWorld",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    alert(msg.d);
                },
                error: function(e) {
                    alert("WebSerivce unreachable");
                }
            });
        });
    </script>



but I am getting error get web service data.
Posted
Updated 23-Dec-13 21:35pm
v3
Comments
JoCodes 24-Dec-13 3:05am    
Whats the problem?
Muhammad Essa Rind 24-Dec-13 3:11am    
I want to get the json data returned from web service and bind with my form but I am getting error
What is that Error?
Muhammad Essa Rind 24-Dec-13 3:21am    
not accessing web service data
JoCodes 24-Dec-13 3:18am    
webmethod container has [System.Web.Script.Services.ScriptService]?

 
Share this answer
 
Change the url to full qualified url in the ajax service call

Eg:

url: "http://localhost:1111/Services/Service.asmx/HelloWorld"
 
Share this answer
 
Comments
Muhammad Essa Rind 24-Dec-13 3:43am    
I have used like this but it did not worked.
Try to debug the code... and find. Only the path may be having the issue...
Rest of the code is fine...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900