开发者

Sending and treating text by get method

开发者 https://www.devze.com 2022-12-31 12:55 出处:网络
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 folding

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

精彩评论

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