views:

111

answers:

1

Hi! How to call webservice through jquery... I tried following code..

$(document).ready(function() {   
         $("#sayHelloButton").click(function(event){   
             $.ajax({   
                 type: "POST",
                 url: "C:/Webservice/Service.asmx/HelloToYou",   
                 data: "{'name': '" + $('#name').val() + "'}",   
                 contentType: "application/json; charset=utf-8",   
                 dataType: "json",   
                 success: function(msg) {   
                     AjaxSucceeded(msg);   
                 },   
                 error: AjaxFailed   
             });   
         });   
     });   
          function AjaxSucceeded(result) {   
              alert(result.d);   
          }   
          function AjaxFailed(result) {   
              alert(result.status + ' ' + result.statusText);   
          }     

My doubt is where my web service should be? Whether I need to publish it and use that path or the service should be within the same solution..

Plz, Clear my doubt

A: 

You need to make sure the URL is on the same server as the HTML page. There are various ways to specify the URL without explicitly writing out the hostname, such as:

url: "/Webservice/Service.asmx/HelloToYou",

C:/ is definitely incorrect, though.

Matthew Flaschen
Actually, My webservice is hosted in the main server in separate path. Now, I need to manage with that. No way to use my web service through jquery now????
Nila