开发者

String replace in var with jQuery

开发者 https://www.devze.com 2023-01-19 01:25 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消