欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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:

image


$.ajax:

image

感覺$.post是用來提交forms的,而要跟wcf ajax service訪問,還必須得用$.ajax來指定Content-Type.

后來找到的資料: http://stackoverflow.com/questions/2845459/jquery-how-to-make-post-use-contenttype-application-json

以上都是按個人理解所寫,有不對之處請指正

相關文章

最新評論