Reputation: 767
I have been facing some weird situation in my jQuery $.getJSON event. I'm able to see the JSON response on my console i.e. the file is getting called but console.log does not seem to work.
Here is the code that I'm writing:
$.getJSON("response.json",function(data){
console.log(data);
});
I tried using single quotes as well but it does not seem to work. This was perfectly working a few days back and now when I tried to add a new function I'm not able to.
I don't know why this error is popping up and I also changed the double quotes to single quotes but that is not solving the problem.
I tried console.log outside the site
Any help will be greatly appreciated.
Thank you.
Upvotes: 1
Views: 1903
Reputation: 27
There may be one possibilities of failure of getJson call that your json file is not in correct format as according to jquery ajax if json is not in proper format then that service will fail. You can check it with below code :
var jqxhr = $.getJSON( "response.json", function(data) {
console.log( "success : " + data);
}).fail(function(jqxhr, tatus, error) {
console.log( "error :" + error );
}).always(function() {
console.log( "complete" );
});
Upvotes: 1
Reputation: 2157
$.getJSON("response.json", function (data) {
console.log(data);
})
.fail(function (jqxhr, status, error) {
console.log('error', status, error) }
);
Upvotes: 3