Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing JSON from REST server
    primarykey
    data
    text
    <p>What I am trying to achieve is to graph a table using Google's graph API, when the page loads, it queries my REST server for the JSON data. This is my Javascript function. </p> <p>The JavaScript console doesn't show any errors.</p> <pre><code> $(document).ready(function() { $.ajax({ url: 'http://localhost:8004/project5', dataType: "json", async:false, error: function(error){ console.debug(error); }, success: function(data) { alert("YESSSSS"); var data = data.results; for(var i=0; i&lt;data.length; i++) { mytable[arraysize] = new terms(data[i].term1, data[i].term2, (data[i].contains)/((data[i].contains)+ (data[i].notcontains))); arraysize +=1; } drawTable(); } }); }); </code></pre> <p>This Is the JSON that is returned when I query the server in my browser using "<a href="http://localhost:8004/project5" rel="nofollow">http://localhost:8004/project5</a>"</p> <pre><code>{ "results":[ { "term1":"test", "term2":"hard", "contains":"32", "notcontains":"55" }, { "term1":"test", "term2":"easy", "contains":"32", "notcontains":"55" }, { "term1":"pizza", "term2":"hut", "contains":"32", "notcontains":"55" } ] } </code></pre> <p>The html contents of content isn't set to "YESSSS" which i was using to test to see if the function was a success. When the page loads, the rest server recognizes that it is queried and successfully returns the JSON, so I believe the problem is getting the data out of the returned JSON. Which is where I am stuck.</p> <p>EDIT: it seems that my success function isn't being called. This is the function that is called in the java REST server, JAX-RS. To produce the JSON.</p> <pre><code> @GET @Produces(MediaType.APPLICATION_JSON) public String getStudentByid(@QueryParam("id") String id) { System.out.println("Queried"); if (id == null) return Terms.stringTerms(container); return Terms.getTermsByFirst(container, id); } </code></pre> <p>I am getting a <code>XMLHttpRequest cannot load http://localhost:8004/project5/terms.json. Origin null is not allowed by Access-Control-Allow-Origin.</code> error now</p>
    singulars
    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