For more information about variables and loop statements, I 'd like to ask about AJAX and PHP. now I want to click a tag on the front-end page, the following figure shows my associated information about the tag clicked above. the code is as follows: index. php & lt; html & gt; & lt; head & gt; & lt; script & nbsp; about variables and loop statements
Hello, everyone, I want to ask a question about AJAX and PHP. now I have encountered such a situation.
I hope that when clicking a tag on the front-end page, the information about the tag I clicked above will be displayed below. the code is as follows:
Index. php
《script》
Suggestions:
Js clienthint code
var xmlHttp
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML=""
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="gethint.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
Processing page code gethint. php
$q=$_GET["q"];
//$select ="select * from test where cid='$q'";
$hint="for($i=0;$i<2;$i++){......}";
//Set output to "no suggestion" if no hint were found
//or to the correct values
if ($hint == "")
{
$response="no suggestion";
}
else
{
$response=$hint;
}
//output the response
echo $response;
?>
Because $ hint needs to be uploaded to the front-end page during processing, I want to pass the loop content after processing the page, but I write as follows: $ hint = "for ($ I = 0; $ I <2; $ I ++ ){......} "; but it only transmits the file string.
Is there any good solution?
Online, etc. thank you! Share:
------ Solution --------------------
It may be:
Not matching
Duplicate id
The pre-bound event is invalid.