Hey everyone,
I was using jquery’s serialize method to post completed form data only to find that a number of my fields were missing.
//Display loader and disable forms disable_form_fields(true); //Post via ajax $.ajax({ type: 'POST', url: 'uploads/add', data: $(form).serialize(), success: function(data, text_status, oHTTP){ handle_form_response(data, text_status, oHTTP, $(form).data('file_id')) }, error: function(){ //Hide loader etc set_form_loading(false); //Unspecified error alert('An error has occurred.'); }, dataType: 'json' });
Thanks to this stackoverflow post I realised that the data wasn’t being serialised because I’d disabled most of the fields beforehand. This was done in order to prevent the user from changing the values. To get around this I simply had to serialise the data BEFORE disabling anything.
//Post via ajax $.ajax({ type: 'POST', url: 'uploads/add', data: $(form).serialize(), success: function(data, text_status, oHTTP){ handle_form_response(data, text_status, oHTTP, $(form).data('file_id')) }, error: function(){ //Hide loader etc set_form_loading(false); //Unspecified error alert('An error has occurred.'); }, dataType: 'json' }); //Display loader and disable forms - DO THIS AFTER SERIALISING disable_form_fields(true);
Let me know if you have any issues.
Leave a Reply