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.
The JavaScript console doesn't show any errors.
$(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<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();
}
});
});
This Is the JSON that is returned when I query the server in my browser using "http://localhost:8004/project5"
{
"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"
}
]
}
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.
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.
@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);
}
I am getting a
XMLHttpRequest cannot load http://localhost:8004/project5/terms.json. Origin null is not allowed by Access-Control-Allow-Origin.
error now
contentelement has a class of "content" and not an ID, correct? I ask because the ID situation seems more likely.window.ajax_result = data. Then you can play with the result in the console.