当谈到AJAX和javascript时,我一般都是垃圾。
我有一个WebMethod:
System.Web.Services.WebMethod公共静态字符串DumpClients() {}
我在一个js文件中有以下代码:
mainScreen.DumpClients = function() {
$('#runclientdumpbtn').attr("disabled", "true");
mainScreen.clientDiv.innerHTML = "";
$("#loadingimageclientdump").show();
PageMethods.DumpClients(mainScreen.DumpClientsCallback, mainScreen.DumpClientsFailed);
}
mainScreen.DumpClientsCallback = function(result) {
if (result) {
$("#loadingimageclientdump").hide();
mainScreen.clientDiv.innerHTML = result;
$('#runclientdumpbtn').removeAttr("disabled");
}
};
mainScreen.DumpClientsFailed = function(error, userContext, methodName) {
if (error) {
// TODO: add your error handling
$("#loadingimageclientdump").hide();
mainScreen.clientDiv.innerHTML = error.get_message();
$('#runclientdumpbtn').removeAttr("disabled");
}
};
Sys.Application.add_load(applicationLoadHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);这很好用(我承认我根本不完全理解这一点),直到我需要从页面访问一个下拉列表。因为它是一个静态方法,我不能直接获取它,所以我想我可以通过webmethod传回这个值。
小问题是我不知道怎么做。我一直在谷歌上搜索,但没有得到任何快速。我正在阅读一本JQuery书籍,并理解更多的基础知识,但目前我无法做到这一点。
我很感谢所有的帮助和建议,很抱歉我可能问了一个有点愚蠢的问题。
发布于 2009-11-22 07:07:19
所以我决定我走错了路,寻找一种更好的方法来调用这个方法,并找到了这个解决方案:
$("#runclientdumpbtn").click(function() {
var selectedreporttype = $("#<%= dropdownpageID %>").val();
$.ajax({
type: "POST",
url: "default.aspx/ExtractContacts",
data: "{outputtype:'" + selectedreporttype + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnContactSuccess,
failure: OnContactFailure,
error: OnContactFailure
});
startContact();
});
[WebMethod()]
public static string ExtractContacts(string outputtype)
{
}希望这对其他人有帮助。
https://stackoverflow.com/questions/1767160
复制相似问题