Reputation: 1844
I'm having a problem running the below script. I'm trying to call a server side method on a button click using jquery. but its not working.I'm neither getting a success nor failure alert to check the script. Please help.
$(document).ready(function() {
var xml=""; // Scope limit covered but not working
$('#<%=btnSave.ClientID %>').click(function(event) {
xml = "<schedule>";
$("#selectedcolumns").find("tr").each(function() {
xml += "<data>";
xml += $(this).find("td").eq(1).html() + "\n";
xml += "</data>";
});
xml += "</schedule>";
//PAgeMethod
PageMethods.GetCustomer(
xml,
function(result) {
alert('success:' + result);
},
function(result) {
alert('error:' + result.get_message());
});
alert(xml);
})
});
In CodeBehind:
[WebMethod]
private void GetCustomer(string NoOfRecords) //just need to reach here.
{
xmlfile(NoOfRecords);
}
Upvotes: 0
Views: 80
Reputation: 70523
This is a scoping issue for the xml value (You declare it in the scope of the callback -- so it will not be visible out side that function.
$(document).ready(function() {
var xml = "";
$('#<%=btnSave.ClientID %>').click(function(event) {
xml = "<schedule>";
$("#selectedcolumns").find("tr").each(function() {
xml += "<data>";
xml += $(this).find("td").eq(1).html() + "\n";
xml += "</data>";
});
xml += "</schedule>";
//This method is defined in the codebehind
PageMethods.GetCustomer(
xml,
function(result) {
alert('success:' + result);
},
function(result) {
alert('error:' + result.get_message());
});
alert(xml);
});
});
Upvotes: 1
Reputation: 3228
WebMethod
's need to be declared static. Here is a good guide covering calling server side methods from jQuery.
Upvotes: 0