JQuyer $.post 與 $.ajax 訪問WCF ajax service 時的問題需要注意的地方
更新時間:2011年09月20日 22:19:14 作者:
我注意到,當在jquery中使用$.post()后,默認的contentType是application/x-www-form-urlencoded 形式進行了urlencoded - 當我的asp.net MVC代碼需要的contentType=application/json
復制代碼 代碼如下:
$.post('<%=this.AppPath %>DataService/InventoryUIService.svc/Rename', ///location.protocol + "http://" + 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, \r\nError message is:" + $(jqXHR.responseText).text();
window.alert(msg);
}
});
TCP Trace截圖
$.post:
$.ajax:
感覺$.post是用來提交forms的,而要跟wcf ajax service訪問,還必須得用$.ajax來指定Content-Type.
后來找到的資料: http://stackoverflow.com/questions/2845459/jquery-how-to-make-post-use-contenttype-application-json
以上都是按個人理解所寫,有不對之處請指正
相關文章
EasyUi tabs的高度與寬度根據(jù)IE窗口的變化自適應代碼
EasyUi tabs的高度與寬度根據(jù)IE窗口的變化自適應代碼,需要的朋友可以參考下。2010-10-10制作高質(zhì)量的JQuery Plugin 插件的方法
最近jquery非常流行,想個性化定制一些功能,就可以將代碼寫成插件的形式,方便使用與修改。2010-04-04關注jquery技巧提高jquery技能(前端開發(fā)必學)
本文給大家介紹jquery前端開發(fā)關注jquery技巧提高jquery技能,對jquery前端開發(fā)感興趣的朋友可以參考下本文2015-11-11