All-Star
40535 Points
6233 Posts
Microsoft
May 04, 2015 10:39 PM|Fei Han - MSFT|LINK
Hi SwanVW,
Thanks for your post.
SwanVW I am learning how to use Ajax to call a server method and return some value. But, my test code can't return a sting.
Please refer to the following sample to call a web method using jQuery AJAX.
$("#btncallwebmethod").click(function () { $.ajax({ type: "Post", url: "AjaxCallWebmethod.aspx/ReturnString", data: "{'firstName':'Swan','lastName':'W'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { var mes = data.d; alert(mes); }, error: function (err) { alert(err); } }); })
[WebMethod] public static string ReturnString(string firstName, string lastName) { string Text = "Hello" + firstName + lastName; return Text; }
For more information about jQuery AJAX, please refer to this link.
http://api.jquery.com/jquery.ajax/
Best Regards,
Fei Han
All-Star
40535 Points
6233 Posts
Microsoft
Re: Call a method from server-side, but I can't get it
May 04, 2015 10:39 PM|Fei Han - MSFT|LINK
Hi SwanVW,
Thanks for your post.
Please refer to the following sample to call a web method using jQuery AJAX.
For more information about jQuery AJAX, please refer to this link.
http://api.jquery.com/jquery.ajax/
Best Regards,
Fei Han