ajax+php的問題
有好幾個checkbox迴圈出來,還有個文字框
HTML code
以下是AJAX:
JScript code
function showInfor(str) { //document.getElementById("txtid").value=str; //var str = document.geElementById("ckID").value; //document.write(str); var xmlhttp; if (id.length==0) { document.getElementById("txtid").value=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { //document.getElementById("show").innerHTML=xmlhttp.responseText; document.getElementById("txtid").value=xmlhttp.responseText; } } xmlhttp.open("GET","showSettle.php?q="+str,true); xmlhttp.send();}
然後是對於的php頁面
PHP code
$db = mysql_connect("localhost","root","1234");mysql_select_db("it database",$db);$q=$_GET['q']; // connecting to database and stuff... echo $q; $temp = mysql_query("SELECT MIS_id FROM materialinstorage WHERE MIS_id = '$q' "); echo $temp;$row = mysql_fetch_array($temp); $id =$row['MIS_id']; echo $id;
現在好像是php那頁面不執行,沒反應啊。
我在ajax裡執行document.write(str);可以得到資料的。
請問哪裡出錯了呀
------解決方案--------------------
弄個google瀏覽器或者firebug一看就知道了!
------解決方案--------------------
探討
他說我id為定義
我把ajax裡的id.length==0改成了xmlhttp==null
可效果還是一樣的,狀態列裡也沒顯示網頁錯誤了
------解決方案--------------------
if (id.length==0)
這個 id 沒有定義
------解決方案--------------------
一步一步調試。首先alert(xmlhttp.responseText); 看能不能彈出php端的輸出。
------解決方案--------------------
HTML code
document.getElementById("txtid").value="";應該是這句,這是什麼錯啊 //跟你這句沒關係的,這句只是設定文字框中的值為空白if (id.length==0){ //是這段的處理,主要是id.length這個沒有定義,不懂這段做什麼,是判斷複選框是否被選? 檢查下這段 document.getElementById("txtid").value=""; return; }