I'm using jQuery 1.7.1, $.ajax, Javascript, JSON and ASP.NET and have some issues with it. When submitting the form to a ASP.NET PageMethod not all the formfields are serialized or are empty. When I debug the code, nothing is wrong, so maybe you can help me.
I submit a form like this in javascript
function SaveFormData() {
var fields = $("form").serializeArray();
var myData = { 'projectId': projectId, 'fields': fields };
myData = JSON.stringify(myData);
$.ajax({
type: "POST",
url: "/w2/AspNetPage.aspx/SaveForm",
contentType: "application/json; charset=utf-8",
timeout: (1000 * 60 * 10),
data: (myData),
dataType: "json",
success: function () {
alert('done');
},
error: function () {
alert('error');
}
});
}
My AspNetPage.aspx contains the webmethod SaveForm:
[WebMethod]
public static string SaveForm(int projectId, field[] fields) {
// do the processing here
}
To read and process the formdata I'm using the class field which is needed to serialize between javascript / JSON and ASP.NET.
public class field {
public string name { get; set; }
public string value { get; set; }
}
My problem is that sometimes not all the formfields are posted, or are empty. I can't find the problem by debugging it, so maybe you can help me with this. Keep in mind that the form can have over a few hundred of form fields.
I was also wondering if the code i'm using now is thread safe, and maybe I have to process my form data different than now.
Please help