龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > Javascript编程 >

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

时间:2012-12-29 08:41来源:未知 作者:admin 点击:
分享到:
提供一篇简单的JQuyer $.post 与 $.ajax 访问WCF ajax service 教程,有需要的朋友参考一下。 代码如下 $.post('%=this.AppPath %DataService/InventoryUIService.svc/Rename', ///location.protocol + // + location.host + loca
提供一篇简单的JQuyer $.post 与 $.ajax 访问WCF ajax service 教程,有需要的朋友参考一下。
 代码如下
$.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());


精彩图集

赞助商链接