Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax - Can't get json data
    primarykey
    data
    text
    <p>I'm quite a beginner in ajax technology. I have a php for execute a mysql_query and I would like to use the result on the client side.</p> <p>My <code>database.php</code>:</p> <pre><code>$q=mysql_query("SELECT name FROM customers"); $res=mysql_fetch_array($q); echo json_encode($res); </code></pre> <p>and my <code>client.php</code></p> <pre><code>&lt;div id="output"&gt;this element will be accessed by jquery and this text replaced &lt;/div&gt; &lt;script id="source" language="javascript" type="text/javascript"&gt; $(function () { $.ajax({ url: 'database.php', //the script to call to get data data: "", dataType: 'json', //data format success: function(data) //on recieve of reply { var name = data[0]; $('#output').html("&lt;b&gt;id: &lt;/b&gt;"+name); } }); }); &lt;/script&gt; </code></pre> <p>This is from some tutorial I've found. And as I saw the <code>database.php</code> works. It prints right data, but in the <code>client.php</code> I can't get anything. What could be the problem?</p> <p>---------EDITED---------</p> <p>So, seems like on the web server runs php 4.4.7 and looks like json_encode() function does not wokrs because of that. I' ve found a "solution". I include upgrade.php, which implemets new methods for older versions of php, as far as i understands. here is the webste of it <a href="http://include-once.org/p/upgradephp/" rel="nofollow">http://include-once.org/p/upgradephp/</a></p> <p>I can't upgrade php version so could this be a good solution? At the moment it does not works</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.
    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