I am trying to use jquery to retrieve data from a JSON file. The file is recognized on the network, but it won't display any data. This is what I came up with, this piece of code is in index.scala.html Please let me know what I am doing wrong. The code outside the script works flawlessly. Also, newbie alert!
<script>
console.log("hi");
$.getJSON('assets/model_meta.json', function(data) {
window.alert(data);
var output="<ul>";
for (var i in data.naraModelMeta) {
output+="<li>" + data.naraModeMeta[i].label + " " + data.naraModeMeta[i].date + " " + data.naraModeMeta[i].c + " " + data.naraModeMeta[i].eps + " " + data.naraModeMeta[i].wp + " " + data.naraModeMeta[i].wn + " " + data.naraModeMeta[i].dictSize + " " + data.naraModeMeta[i].fromDate + " " + data.naraModeMeta[i].toDate + " " + data.naraModeMeta[i].vectorNum + "</li>";
}
output+="</ul>";
document.getElementById("meta_data").innerHTML=output;
});
</script>
this is what i have in controller:
List data = Arrays.asList("foo", "bar");
return ok(Json.toJson(data));
but the List and toJson show up as errors.
I also have a route set up. I am referencing this website if it helps: http://java.dzone.com/articles/jquery-ajax-play-2
Add two import 1) import java.util.Arrays; // for array 2)import play.libs.Json; //for json
then try running url in browser , you will be able to see json response.