所以我有一个服务器端 ajax php 文件:
$thing = "\n\ncode\n";
echo(trim($thing, '\n'));
但是当我使用这个 php 文件进行 ajax 调用时,responseText 没有删除换行符!
var xhr7 = new XMLHttpRequest();
xhr7.onreadystatechange = function() {
if (xhr7.readyState == 4) {
if (xhr7.status == 200) {
alert('trying');
alert(xhr7.responseText);
chrome.tabs.executeScript(null, {code: xhr7.responseText });
} else {
alert("404 server side ajax file DOES NOT EXIST");
}
}
};
xhr7.open('POST', 'http://texthmu.com/Devin/HMU%20ext/Post-jsfile-forItsCode.php', true);
xhr7.setRequestHeader("Content-type","application/x-www-form-urlencoded"); //following w3
xhr7.send(); `
最佳答案
\n 需要用双引号而不是单引号
echo(trim($thing, "\n"));
当值包含在单引号中时,它会被解析为文字。在本例中,使用 \n
而不是您要 trim 的换行符。
关于php trim 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6367291/