I am rather rubbish when it comes to AJAX and javascript on general.
I have a WebMethod:
[System.Web.Services.WebMethod] public static string DumpClients() {}
I have this code in a js file:
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, u开发者_如何学PythonserContext, 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);
This worked fine, (I admit I do not fully understand this at all), until I needed to access a dropdownlist from the page. As it is a static method I can not directly get it, so I thought I could pass the value back through the webmethod.
The small problem is I have no idea how. I have been Googling it but am not getting anywhere fast. I am working my way through a JQuery book and understanding more of the basics but this is way beyond me at this moment.
I appreciate any and all help and advice, and sorry that I am probably asking a bit of a stupid question.
So I decided I was going completely the wrong way and looked for a better way to call the method and found this solution:
$("#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)
{
}
Hope this helps someone else.
精彩评论