Reputation: 1306
I am using CKEditor and would like to serialize the textarea data along with all of the other elements. Is this possible?
I would like to append the taData to vals if possible.
var vals = $("#post").find('input,select').serialize();
var taData = CKEDITOR.instances.ta1.getData();
Upvotes: 22
Views: 27551
Reputation: 816462
.serialize
returns a string, so you can always modify the string, but I would not recommend this, string manipulation can get messy.
Instead, use .serializeArray
[docs] to create an array representation of the data and then add the data to it. Each element of the array is an object with a name
and value
property:
var vals = $("#post").find('input,select').serializeArray();
vals.push({name: 'nameOfTextarea', value: CKEDITOR.instances.ta1.getData()});
All jQuery Ajax methods will understand this structure and serialize the data properly. In case you want to create a serialized string (just like .serialize
), you can pass the array to $.param
[docs]:
var query_string = $.param(vals);
Upvotes: 47