0

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

Ruutert
  • 395
  • 1
  • 7
  • 18
  • Where are the fields missing sometimes: server or client? – Marc Oct 17 '12 at 08:15
  • problem solved!, I used a static field to store my field[], that was very dangerous, so I've now a new solution without static stuff. jQuery and SerializeForm works great! No problems there. It was my mistake to use static fields / properties to process the form data – Ruutert Feb 14 '13 at 12:05

1 Answers1

0

Please make sure your form fields are not disabled.

Disabled fields can't be posted to server

Refer

values of disabled inputs will not be submited?

submit disabled fields

Hope this may helpful!

Community
  • 1
  • 1
Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120