This is a follow up using the code from my previous question:
Why wont js read text box values
My code behind methods are already displayed in that post.
My script works fine with the code behind but when I am trying to retrieve the return value I am getting a return value of "undefined".
The JS code is simple:
var answer = PageMethods.saveCat(CategoryName, ParentID, CategoryID, CatChk);
window.alert(answer);
I have also tried:
windows.alert(String(answer));
but I keep getting an undefined value. I have searched around but have only been able to find solutions using a drawn out $.ajax syntax and was wondering is there a simple way to grab the string value returned by my web method similar to the code I am trying to get to work instead of writing 10 - 15 lines of code?
Thanks for the help.
Thanks to Karthik Ganesan's comment I was able to get on the right track using this link: mindfiresolutions.com/Using-PageMethods-in-ASPNET-2467.php
My resulting code was:
PageMethods.saveCat(CategoryName, ParentID, CategoryID, CatChk, onSuccess, onFailure);
function onSuccess(result)
{
alert(result);
}
function onFailure(result)
{
alert("There was an error saving the category.");
}
I am posting this hoping it helps out other newbies to JS.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.