jquery $.post 与 $.ajax 访问WCF ajax service
提供一篇简单的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()); |
精彩图集
精彩文章