我有這個PHP文件(剝離下來的重要組成部分)JavaScript的AJAX PHP調用返回3個字符
getBoundaries.php
<?php
$t = "";
//$t = "t";
Header("Content-type: text/plain; charset=utf-8");
echo ($t);
?>
和這個JavaScript調用Ajax:
function anyname(){
var xhttp;
var query = "tid=1&pid=1";
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var temp = xhttp.responseText;
if (temp == ""){
console.log("ein leerer string");
}
else{
for (i = 0; i < temp.length; i++){
console.log(temp.charCodeAt(i));
}
}
}
}
xhttp.open("POST", "getBoundaries.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(query);
}
console.log
與$t=""
的輸出爲32,10,32。
console.log
與$t="t"
的輸出是116,32,10,32。
所以,我的問題是:爲什麼不是一個空字符串作爲responseText返回?這些額外的3個字符添加在哪裏?我的假設:echo
php-command添加了這三個字符。
有什麼建議嗎?
也許你'>>'後面有一些空格(結束標記) –
另外,請注意結束標記不是強制性的。當然,如果在同一頁面上使用PHP和HTML代碼,則必須使用它.. –
看起來更像是一個空格之後?>然後是一個帶有空格的新行 –