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();
.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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With