I am trying to update some text within <span>
fields on a parent form via a modal. To do this I am using an AJAX call on the modal form to retrieve the new user entered values. Once the "Save" button is clicked, the modal form should retrieve the textbox values and send them back.
However I am unable to pass any values back. When debugging in the function that creates a Javascript array, the values exist and are correct. However once I try to use the data
property of the AJAX call (ex: data.Address
), it returns undefined.
Here is my code for the AJAX call:
$.ajax({
type: 'POST',
data:
{
ID: $("#clientID-@Model.Id").val(),
Address1: $("#clientAddress1-@Model.Id").val(),
Address2: $("#clientAddress2-@Model.Id").val(),
City: $("#clientCity-@Model.Id").val(),
Province: $("#clientProvince-@Model.Id").val(),
PostalCode: $("#clientPostalCode-@Model.Id").val(),
PhoneNumber: $("#clientPhoneNumber-@Model.Id").val()
},
success: function (data) {
//$("#Address1-@Model.Id").html(data.Address1);
alert(data); //prints the entire HTML for the form
alert(data.ID); //prints undefined
alert($("#clientID-@Model.Id").val()); //prints the correct value - 2827
alert("Data logged!");
},
error: function (data) {
alert("Error occurred!");
}
});