I am trying to post a form to my web service with no great success so far.
Before posting to the server I am converting the form to an object.
I get an error when posting the form Object
to my Asmx
web service.
My Ajax:
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");
}
});
My asmx:
[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; }
}
More information: When debugging these are the values:
What am I doing wrong?