Ajax + php problems

Source: Internet
Author: User
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 ;}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.