I'm struggling to successfully post a form to my web service. Before sending it to the server, I am converting the form into an object. However, I encounter an error when trying to post the form as an Object to my Asmx web service.
Here is my Ajax code:
var formObject = $(form).serializeObject();
var formData = JSON.stringify(formObject);
$.ajax({
type: "POST",
url: "./Service.asmx/PostAutomaticRule",
data: { myObject: formData },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert("success");
},
error: function (response) {
alert("Error");
}
});
And here is my asmx endpoint:
[WebMethod(EnableSession = true)]
public void PostAutomaticRule(MyClass myObject)
{
Debug.WriteLine(myObject);
}
}
[Serializable]
public class MyClass
{
public string automaticRuleName { get; set; }
public string action { get; set; }
public string increaseBudgetByValue { get; set; }
public string increaseBudgetMaximumBudget { get; set; }
}
Upon debugging, these are the values that pop up:https://i.sstatic.net/wQpS2.png.
Any ideas on what could be going wrong?