Here's a basic example of submitting JSON to a web method.
Model
public class FormData
{
public DateTime date { get; set; }
public int entityId { get; set; }
public string email { get; set; }
public string ssn { get; set; }
public string address1 { get; set; }
public string address2 { get; set; }
public string headName { get; set; }
public string landlordName { get; set; }
public string landlordPhone { get; set; }
public string phone { get; set; }
public string image { get; set; }
}
Web Method
[WebMethod(EnableSession = true)]
public static FormData MyFunction(FormData formData)
{
return formData;
}
JavaScript
$("#<%=btnSendAjax.ClientID%>").on('click', function (e) {
e.preventDefault();
var data = {
formData: {
date: '2022-03-31',
entityId: 1,
email: 'email@email.com',
ssn: '123456789',
address1: '123 West',
address2: '',
headName: 'name',
landlordName: 'landlord',
landlordPhone: '123654987',
phone: '852369741',
image: 'dsfasdfasdfwqwefasdadsf'
}
};
$.ajax({
type: "POST",
contentType: "application/json",
url: "default.aspx/MyFunction",
data: JSON.stringify(data),
})
.done(function (data) {
console.log("success");
console.log(data);
})
.fail(function (jqXHR, textStatus, c) {
console.log("failure");
console.log(textStatus);
});
});