String replace in var with jQuery
I am having trouble trying to get all my form data and break it down for debugging. I just want to replace the "&" with a new line.
var formData = $("#customer_detail开发者_Go百科s_form").serialize();
var debugData = formData.text().replace(/&/g,'\n');
Thanks
jQuery's .serialize()
method returns a String, not a jQuery object, so get rid of .text()
.
var formData = $("#customer_details_form").serialize();
var debugData = formData.replace(/&/g,'\n');
The variable formData
has the string, so text()
shouldn't be necessary.
Try formData.replace(/&/g,'\n');
.
formData
is an ordinary string.
Remove the .text()
call.
精彩评论