Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX & JSON - the status is 0
    text
    copied!<p>I created a json file with some objects, and I build HTML page that if I press a button, all the objects in the json file will apear on the page. I run the JSON file with ECLIPSE on the server, but when I try to access this file with AJAX , the readyState is 0 , and I can't get access to the file. here's the code:</p> <p>JSON file:</p> <pre><code>{ "Dogs": [ { "Id": "5435", "Name": "ee", "Type": "Pudel", "Picture": "pudel.jpg" }, { "Id": "3321", "Name": "Lali", "Type": "Labrador", "Picture": "labrador.jpg" } ] } </code></pre> <p>JS file with the function that using AJAX:</p> <pre><code>function show(){ xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { // alert(xhr.status); it's shows 0 and than alert the error below if (xhr.status == 200) { var dataObject = eval("(" + xhr.responseText + ")"); var output = dataObject.Id; output += dataObject.Name; output += dataObject.Type; output += '&lt;img src='+dataObject.Picture+'width="150" height="150"&gt;'; document.getElementById("result").innerHTML = output; } else { alert("Error! Couldn't get json data"); } } }; xhr.open("GET", "Objects.json", true); xhr.send(); } </code></pre> <p>and the html file:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="JS.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;button id="btn" onclick="show()";&gt;Press Me&lt;/button&gt; &lt;br&gt; &lt;div id="result"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Where is the problem?</p>
 

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