Thursday, July 8, 2010

How to do jquery postback using C#

simple and sweet C# function dont forget attribute.



[System.Web.Services.WebMethod]
public static string GetCustomerCreditCardInfo(string accountNumber)
{
System.Data.DataTable dt = Order.GetOrderHistoryByAccountId(int.Parse(acountNumber));
return "";
}

place this text in a jquery function

$.ajax({ type: "POST", url: "PosOrderEntry.aspx/GetCustomerCreditCardInfo", data: "{accountNumber : '" + accountId + "'}", contentType: "application/json; charset=utf-8", dataType: "json",
success: function(msg) {
if (msg.d == "") {
alert('nothing'); //failure
}
alert(msg.d); //success
}
});
//notice that the accountNumber has to have the same name as the c#function argument name

No comments:

Post a Comment