Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP and Ajax a onclick function
    text
    copied!<p>I have a menu, I want when select item from menu, the content displays, but I can't call ajax function. When I click in item from menu, in address line was appeared only id of selected item:</p> <pre><code>http://localhost:8080/treeview/#2 </code></pre> <p>HTML code from a browser:</p> <pre><code>&lt;a onclick="callPage(1)"; href="#1 "&gt; &lt;span style="color:yellow";&gt;item1&lt;/span&gt;&lt;/a&gt; </code></pre> <p>The PHP code, where I form html code:</p> <pre><code> $out .= '&lt;li id="'.$item['id'].'"&gt; &lt;label for="subfolder2"&gt;'; $out .= '&lt;a onclick="callPage('.$item['id'].')"; href="#'.$item['id'].' "&gt; &lt;span style="color:'.$item['color'].'";&gt;'.$item['title'].'&lt;/span&gt;&lt;/a&gt;'; $out .= ' &lt;/label&gt; &lt;input type="checkbox" id="subfolder2"/&gt;'; </code></pre> <p>AJAX function:</p> <pre><code>// JavaScript Document function callPage(id) { var xmlhttp; 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 &amp;&amp; xmlhttp.status==200) { document.getElementById("pageContent").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","content.php?id="+id,true); xmlhttp.send(); } </code></pre> <p>A Content file, I was tested, he work well, when I take him in address bar in browser:</p> <pre><code>&lt;?php function __autoload($class){ include_once($class.".php"); } $id=$_REQUEST['id']; $db = new oopCrud(); $rty = $db-&gt;getById($id); echo $rty['title']; echo $rty['color']; ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload