calling a simple WCF Service from jQuery

后端 未结 3 1866
臣服心动
臣服心动 2021-01-03 03:49

I have a very simple WCF Service called pilltrkr.svc. I\'m trying to call this service from jQuery via the following code:

    var jsondata = JSON.stringif         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-03 04:04

    what i found in google, might help you.

    $(document).ready(function() {
             $("#sayHelloButton").click(function(event){
                 $.ajax({
                     type: "POST",
                     url: "dummyWebsevice.svc/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);
              }  
    
    [WebMethod()]
    public static string sayHello()
    {
        return "hello ";
    } 
    

提交回复
热议问题