$.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
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class VisitorWS : System.Web.Services.WebService {
[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.