0
我有這樣的事情:的getJSON請求發送具有多串
code.js
var params = {
option1 : encodeURIComponent("text\n text\n text\n\n\n"),
option2 : encodeURIComponent("\n\n\n text")
};
$.getJSON("/update_user_info", params, function(data) {});
/update_user_info
<?php
foreach($_GET as &$data) $data=urldecode($data);
/*CODE*/
echo json_encode($some_result);
?>
但我\n
被移除或替換成whitespaces
是否可以在GET請求中保留換行符?
P.S:我有充分的AJAX網站,所以我不能定期「POST」方法使用表單,提交按鈕等等。
確定那些「空格」不換行? –
@火箭我用preg_replace(「/(\ s)+ /」,「
」,$ my_data);但結果是一行字符串。我還使用了:str_replace(「\ n」,「
」,$ my_data);但結果又是一行字符串。 – John
試試'nl2br($ my_data)'。 –