jQuery Ajax GET JSON jQuery Ajax GET JSON ajax ajax

jQuery Ajax GET JSON


It's possible that piece.json doesn't returns valid JSON so jQuery discards it. Try to change dataType: "json" to dataType: "html" and see if the alert(data) shows the output. If the alert shows your data then there's a syntax error in the json object.


This worked for me:

$.getJSON( "example.json", function(data) {   console.log( "success" );}).done(function() {   console.log( "second success" );}).fail(function() {  console.log( "error" );}).always(function() {   console.log( "complete" );});

Replace example.json, with the url or path of your json file.Note the use of $.getJSON vs $get . Here's my reference: http://api.jquery.com/jquery.getjson/


Try changing the datatype to JSONP. It's usually to overcome the Same Origin Policy but may work in your case.

$.ajax({    url: '/piece.json',    type: "GET",    dataType: "jsonp",    success: function (data) {        alert(data);    }});