ajax+php的有關問題

來源:互聯網
上載者:User
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;  }
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.