Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't get JSON results from file in XMLHttpRequest
    primarykey
    data
    text
    <p>I'm having problems getting my request filled with the data from a json file... Data is pulled from Mysql DB and formatted in a JSON file in the scripts dir... </p> <p>Could there be a problem with the GET request ? I just want the json file returned so i could work with the key/val pairs inside of it ... </p> <p>Any suggestions would be appreciated.</p> <pre><code>function fetchData($str){ $queryAll = "select name,value,date from chart where id &lt;= (select max(id) from chart) limit 50"; $dateValue = mysql_query($queryAll); $pushed = array(); while($row = mysql_fetch_array($dateValue,MYSQL_ASSOC)){ $key = array_shift($row); $value = array_shift($row); $date = array_shift($row); if(strcmp("$str",$key) == 0){ $myArray = array($key, $value, $date); array_push($pushed,$myArray); } } $jsonFile = json_encode($pushed); $jsonOpenFile = fopen("../scripts/$str.json","w+") or exit("Unable to open file!"); $jsonWriteOut = fwrite($jsonOpenFile,$jsonFile); } fetchData("blabla"); ?&gt; </code></pre> <pre><code>&lt;script&gt; function Graph(JsonVal){ var xmlhttp = new ajaxRequest(); 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) { var jsondata=eval("("+xmlhttp.responseText+")"); var returned = jsondata.items var output; for(var i=0; i&lt;returned.length;i++){ output += "&lt;p&gt;"; output += returned[i]; output += "&lt;/p&gt;"; } document.getElementById("MyGraph").innerHTML=output } } xmlhttp.open("GET","../scripts/"+JsonVal+".json",true); xmlhttp.send(null); } &lt;/script&gt; &lt;div id="MyGraph" onload="Graph();"&gt;&lt;/div&gt; </code></pre>
    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.
    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