My goal is to create a graph from a table using Google's graph API. Upon loading the page, it retrieves JSON data from my REST server with this JavaScript function.
No errors are shown in the JavaScript console.
$(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();
}
});
});
Here is the JSON data retrieved when querying the server in the 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"
}
]
}
Despite my efforts, the HTML content is not displaying "YESSSS" as expected for testing the success of the function. The REST server recognizes the query and returns the JSON data, leading me to believe the issue lies in extracting the data from the JSON response.
UPDATE: It appears that the success function is not being executed. This function is called in the Java REST server, JAX-RS, to generate 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);
}
Now I am encountering an error stating
XMLHttpRequest cannot load http://localhost:8004/project5/terms.json. Origin null is not allowed by Access-Control-Allow-Origin.