[jquery ajax]jquery $.post 与 $.ajax 访问WCF ajax service

更新时间:2017-04-22    来源:WCF    手机版     字体:

【www.bbyears.com--WCF】

 代码如下 $.post("<%=this.AppPath %>DataService/InventoryUIService.svc/Rename", ///location.protocol + "//" + location.host + location.pathname + "/Rename",
                               odata,
                                 function (result) {
                                     $dialogProcessing.dialog("close");
                                     if (result.Success) {
                                         alert("Success");
                                     }
                                     else {
                                         var msg = "Your submit fauiler, Detail message is:" + result.ErrorMessage;
                                         window.alert(msg);
                                     }
                                 },
                               "json");
               $.ajax({
                   url: "<%=this.AppPath %>DataService/InventoryUIService.svc/Rename",
                   type: "POST",
                   contentType: "application/json",
                   dataType: "json",
                   data: odata,
                   success: function (result) {
                       if (result.Success) {
                           alert("Success");
                       }
                       else {
                           var msg = "Your submit fauiler, Detail message is:" + result.ErrorMessage;
                           window.alert(msg);
                       }
                   },
                   error: function (jqXHR, textStatus, errorThrown) {
                       var msg = "Your submit throw a error, rnError message is:" + $(jqXHR.responseText).text();
                       window.alert(msg);
                   }
               });

$.post是用来提交forms的,而要跟wcf ajax service访问,还必须得用$.ajax来指定Content-Type

You can"t send application/json directly -- it has to be a parameter of a GET/POST request.

So something like

 代码如下

$.post(url, {json: "...json..."}, function());

本文来源:http://www.bbyears.com/asp/32103.html

猜你感兴趣

热门标签

更多>>

本类排行