开发者

Sending and treating text by get method

Guys, could you help me with treating text sent with GET method. How to detect and treat line foldings in text? The text is sent from textarea through AJAX using GET method. How to detect line foldings in text when it is sent in GET method?

And I want to replace a开发者_JS百科ll line foldings with special character for example like "|" before sending to PHP script.

How to do it?


You can do this with the JavaScript string replace function.

s = "a\rb\nc\r\nd";
s2 = s.replace(/(\r\n|\r|\n)/g, "|");

s2 now equals: "a|b|c|d", no matter whether line endings are \r\n, \n, or \r.


<textarea id="message"></textarea>

<script type="text/javascript">
  var msg = document.getElementById("message").value;
  msg = msg.replace(/\n/g, "|");

  // Then, just send message through AJAX.
</script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜