how do I send stuff to method using the JQuery Ajax method
- by nisardotnet
$.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.