how do I send stuff to method using the JQuery Ajax method
Posted
by nisardotnet
on Stack Overflow
See other posts from Stack Overflow
or by nisardotnet
Published on 2010-04-12T19:44:40Z
Indexed on
2010/04/12
20:03 UTC
Read the original article
Hit count: 248
$.ajax({
type: "POST",
url: "WebService.asmx/AddVisitor",
data: "{'fname':'dave', 'lname':'ward'}",
contentType: "application/json; charset=utf-8",
dataType: "json"
});
I have an Asp.Net WebMethod that takes a firstName, lastName.....as a parameter, how do I send that stuff to that method using the JQuery Ajax method. if i hardcode the above it works without any problem
but if i pass dynamic it fails
var firstName = $("[id$='txtFirstName']");
var lastName = $("[id$='txtLastName']");
//data: "{'firstName':'Chris','lastName':'Brandsma'}"<br>
data: "{'firstname':'" + escape(firstName.val()) + "','lastName':'" + escape(lastName.val()) + "'}",
my WebMethod looks like this
[WebMethod]
public bool AddVisitor(string firstName, string lastName)
{
return true;
}
what wrong here? i have tried with eval and escape none of that works.
Thanks for any help.
© Stack Overflow or respective owner