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 xmlhttpfunction 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=" +strurl=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) { C14/>xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP"); } }return XmlHttp;}
Handling page Code gethint.php
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!
Reply to discussion (solution)
Can be achieved through eval and create_function
Thanks to both Eval and create_function. Can you give me an example? Because I just tried it with Eval. No, the operation is as follows
$hint = ' for ($i =0; $i <2; $i + +) {...} ';
Eval ("\ $hint = \" $hint \ ";");
$hint = ' for ($i =0; $i <2; $i + +) {} '; eval ($hint); Echo $i; 2
$hint = ' for ($i =0; $i <2; $i + +) {} '; if (2 = = eval ($hint. ' return $i; ')) echo ' OK ';
$hint = ' for ($i =0; $i <2; $i + +) {} '; if (2 = = eval ($hint. ' return $i; ')) echo ' OK ';
Amount Still a little not understand, sorry, trouble look at the following code:
$hint = ' for ($i =0; $i <2; $i + +) {123} ';
if (2 = = eval ($hint. ' return $i; '))
echo ' OK ';
I want to show two layers
If the program is written
for ($i =0; $i <2; $i + +) {123}
Do you think it's right?
If the program is written
for ($i =0; $i <2; $i + +) {123}
Do you think it's right? Amount Because it is hoped to be able to loop through multiple layers out, the amount. It's not the way to write about yourself. I'm sorry
$hint = ' for ($i =0; $i <2; $i + +) {} '; if (2 = = eval ($hint. ' return $i; ')) echo ' OK ';
Amount Can you guide me?
$hint = ' for ($i =0; $i <2; $i + +) {} '; if (2 = = eval ($hint. ' return $i; ')) echo ' OK ';
has solved the problem of layer loops, but the original layer of some JS action, through the eval out there is no effect. What is the reason for this?
May be:
Tag does not match
Duplicate ID
Invalid pre-bound event