[英]jQuery Ajax Call to asp.net webmethod
誰能說出如何在Jquery Ajax調用中指定成功函數。 假設我有如下功能
getComments(data,url,SucessFunction,FailurFunction) {
var list = [data];
var jsonData = JSON.stringify({ list: list });
$.ajax({
type: "POST",
url: url,
data: jsonData,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response, status) {
var List = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
$.each(List, function() {
if (this['Cid'] != "1000")
$('#' + ddlCities).append('<option value="' + this['Cid'] + '">' + this['CityCode'] + '</option>');
else ($('#outerDiv').html(this['City']));
});
}
});
}`
在此如何定義成功函數,錯誤函數
喜歡
getComments(data,url,SucessFunction,FailurFunction) {
var list = [data];
var jsonData = JSON.stringify({ list: list });
$.ajax({
type: "POST",
url: url,
data: jsonData,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: SucessFunction
}
});
}
提前致謝。
僅供您參考:根據您的需求
AjaxPageMethod("your method", { " ": " " }, ajaxCallSuccess, ajaxCallFailure, "page name");
function ajaxCallSuccess(response) {
var msg = response.d;
$("tab").html(msg);
}
function ajaxCallFailure(response) {
var msg = response.d;
}
函數AjaxPageMethod(fn,reqObject,successFn,errorFn,aspxPage){
var dataObject = JSON.stringify(reqObject);
//Call the page method
$.ajax({
async: false,
type: "POST",
url: aspxPage + "/" + fn,
contentType: "application/json;",
data: "{'reqObject':" + dataObject + "}",
dataType: "json",
success: successFn,
error: errorFn
});
};
我發現使用Web方法很不穩定,您可能想采用稍微不同的方法,而不是使用Web方法,而是使用啟用了Ajax的WCF服務?
這是有關如何使用wcf進行設置以構建快速,精簡的Web應用程序的博客文章
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.