// Initialize the object, before adding data to it.
var NewPerson = new Object();
NewPerson.FirstName = $("#FirstName").val();
NewPerson.LastName = $("#LastName").val();
NewPerson.Address = $("#Address").val();
NewPerson.City = $("#City").val();
NewPerson.State = $("#State").val();
NewPerson.Zip = $("#Zip").val();
In actual I'm populating and sending an array of NewPerson objects. I'm using all the properties in my javascript but when I make ajax call like below, I want to only send two of the properties say for FirstName
and LastName
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "PersonService.asmx/AddPerson",
data: "{'NewPerson':" + JSON.stringify(NewPerson) + "}",
dataType: "json"
});
NOTE: I'm using an array not a single object of NewPerson
. The above code is just for example.