Ajax + php has several checkbox loops and a text box HTMLcode & lt; inputname & quot; ckID [] & quot; type & quot; checkbox & quot; ckID. $ row [MIS_id]? & Gt; & quot; value & quot; & lt ;? $ Row [MIS ajax + php problems
There are several checkbox loops and a text box
HTML code
The following is 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();}
Then, for the php page
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;
It seems that the page of php is not executed, and it does not respond.
I execute document. write (str); in ajax to get the data.
What's wrong?
------ Solution --------------------
Get a google browser or firebug!
------ Solution --------------------
Discussion
He said that my id is defined
I changed id. length = 0 in ajax to xmlhttp = null.
The effect is the same, and the webpage error is not displayed in the status bar.
------ Solution --------------------
If (id. length = 0)
This id is not defined
------ Solution --------------------
Step by step debugging. First, alert (xmlhttp. responseText); check whether the php output can be displayed.
------ Solution --------------------
HTML code
Document. getElementById ("txtid "). value = ""; it should be this sentence. what is the error? // it does not matter to you. this sentence only sets the value in the text box to null if (id. length = 0) {// is the processing of this segment, mainly id. length is not defined. I don't know what to do in this section. is it to determine whether the check box is selected? Check the document. getElementById ("txtid"). value = ""; return ;}