I made a little script that send a textarea content to PHP page with get ajax request:
$.get('./data/pages/admin/actions.php?savepost=1','&post_id=' + $(box).attr('id') + '&text=' + new_text,'text');
new_text get content from textarea with val();
When I save the text from php it has no character. Some1 can solve my problem? Thanks
Use encodeURIComponent()
to encode the newline character to the right url notation.
You're not encoding your data at all, so lots of things are going to blow up (percent signs, ampersands, ...). Either use encodeURIComponent
on each bit or (and this is easier) let jQuery do it for you:
$.get('./data/pages/admin/actions.php?savepost=1', {
post_id: $(box).attr('id'),
text: new_text
}, 'text');
See the docs for details on the data parameter.
before passing new_text
try doing this first.
new_text.replace("
","%0D%0A");