0
我在使用AJAX從我的代碼獲取結果時沒有得到響應。同時發送參數到文件我的代碼工作正常...即發送參數到文件,因爲我已經使用警報消息檢查.. 但我的PHP文件沒有顯示任何響應。使用ajax獲取響應時出現問題
AJAX CODE。
function viewsg(){
document.getElementById('sgwaitingmsg').innerHTML = "Just a second...";
var childid = encodeURIComponent(document.getElementById('childsgselect').value);
var parameters ='childid=' + childid;
http.open('POST', 'fetchsg.php', true);
http.send(parameters);
//alert(parameters);
http.onreadystatechange = function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("sgwaitingmsg").innerHTML=xmlhttp.responseText;
}
}
}
PHP代碼。
<?php
//$_REQUEST["childid"];
//$_REQUEST["nocache"];
echo $_REQUEST["childid"];
?>
HTML代碼。
<label id="sgwaitingmsg"></label>
<select id="childsgselect" onchange="viewsg()" >
<option value="">Select Child</option>
<?php while($result=mysql_fetch_assoc($child)){print '<option value="'.$result["snum"].'">'.$result["sfname"].'</option>'; }?>
</select>
它同樣,沒有獲取響應文本。 –
@ user921300:你的JS有sytnax錯誤。看看我的編輯 – genesis
@那我已經試過了'if(xmlhttp.readyState == 4 && xmlhttp.status == 200)'。但那也行不通。 –