[英]Ajax send and adds hidden characters
I want to send something from one php site to another. 我想从一个PHP站点向另一个站点发送内容。 At the first site, everything seems fine.
在第一个站点上,一切似乎都很好。 The string seems like
字符串看起来像
--show="author,book,text/n
--show =“ author,book,text / n
but when i check the string after receiving it looks like 但是当我收到后检查字符串时,它看起来像
--show="author,book,text/r/n
--show =“ author,book,text / r / n
there is the problem, somehow it adds /r
in the end. 存在问题,它最终以某种方式添加了
/r
。
First php: 第一个php:
$(document).ready(function() {
$("#column_button").click(function(){
var selected = [];
$.each($("input[name='checkbox_columns']:checked"), function(){
selected.push($(this).val());
});
var data = new FormData();
data.append("data", "--show=" + selected);
//alert(JSON.stringify(selected));
var ajax = (window.XMLHttpRequest) ? new XMLHttpRequest() : new activeXObject("Microsoft.XMLHTTP");
ajax.addEventListener("load", statusHandler2, false);
ajax.open( 'post', 'showParameter.php', true );
ajax.send(data);
_("column_button").disabled=true;
});
});
Second php: 第二个php:
if(!empty($_POST['data'])){
$data = $_POST['data'];}
So selected shows it right, but if i check the $data in the second php, it's wrong. 所以选择显示它正确,但是如果我在第二个php中检查$ data,那是错误的。
This appears to be an issue where the servers are using different line ending types. 当服务器使用不同的行尾类型时,这似乎是一个问题。 Unix systems (Linux, BSD, etc) use
\\n
( LF
) by default, MacOS uses \\r
( CR
) where as Windows systems use \\r\\n
(also known as CRLF
). Unix系统(Linux,BSD等)默认情况下使用
\\n
( LF
),MacOS使用\\r
( CR
),而Windows系统使用\\r\\n
(也称为CRLF
)。 You may need to change your character encoding on one of the servers to the other. 您可能需要将其中一台服务器上的字符编码更改为另一台。
CR
= carriage return LF
= line feed CR
=回车LF
=换行
You could use code that will substitute the CRLF or CR with just an LF. 您可以使用仅用LF代替CRLF或CR的代码。 This page shows how you can achieve this simply.
此页面显示了如何简单地实现这一目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.