Questions about variables and circular statements
Daniel, the news wants to ask a question about Ajax and PHP, and now I have a situation like this
I want the front-end page to click on a tag, below can display my information about the above click on the tag to associate the data, the code is as follows
index.php
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;
}
Handling 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 the processing page $hint is needed to upload to the front page, so I hope that the processing page will loop the content is done after the transfer, but I wrote: $hint = "for ($i =0; $i <2; $i + +) {...}"; He can only pass the file string.
So please, do you have any good solutions?
Online, etc., thank you all!
Share to:
------Solution--------------------
May be:
Tag does not match
Duplicate ID
Invalid pre-bound event