Note that there are some explanatory texts on larger screens.

plurals
  1. POPass JSON AJAX reply to PHP
    primarykey
    data
    text
    <p>I have a script which uses AJAX to connect to a PHP script which queries a database and returns some values. The code of which is below:</p> <pre><code>&lt;script&gt; function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; 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 &amp;&amp; xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","ajaxphp.php?ID="+str,true); xmlhttp.send(); } &lt;/script&gt; &lt;select id="users" name="users" onchange="showUser(this.value)"&gt; &lt;option value=""&gt;Select a person:&lt;/option&gt; &lt;!-- PHP populates this dropdown box --&gt; &lt;/select&gt; &lt;div id="txtHint"&gt;&lt;b&gt;Selected user info will be listed here.&lt;/b&gt;&lt;/div&gt; </code></pre> <p>Right now the txtHint div will return anything the ajaxphp.php script prints. This isn't very flexible, however. What I want to do is create an array in ajaxphp.php and use json_encode() to pass the results back. </p> <p>The problem I'm having is I don't know how to get the original script to grab the results so I can do useful things with them. Right now I can make it return a JSON array which will appear in the txtHint div but I've no idea how to get PHP to actually read that information so I can do something with it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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