How can I merge a serialized form with aoData?
How can I merge a serialized form with aoData?
I am trying to use DataTables with AJAX and the fnServerData option in Rails. However, I can't do a GET as each request is actually posting a serialized form from the page. It's no problem to do the POST with the fnServerData option though. However, I run into a problem trying to figure out how to merge aoData, which appears to be an array of objects, and my call to:
[code]$("#attributeform").serialize()[/code]
Is there some way I can put these together so that I can submit them to my controller?
FYI I'm doing this in Rails without the RailsTable method.
[code]$("#attributeform").serialize()[/code]
Is there some way I can put these together so that I can submit them to my controller?
FYI I'm doing this in Rails without the RailsTable method.
This discussion has been closed.
Replies
Thanks very much for the donation :-). What I think you want to do in this case is use $.serializeArray ( http://api.jquery.com/serializeArray/ ), rather than just $.serialize. This will give you the name/value pairs needed for the jQuery Ajax. Something like this:
[code]
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.concat( $("#attributeform").serializeArray() );
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
[/code]
That will combine the aoData array from DataTables with the serliazed form.
Regards,
Allan