Reputation: 27
Having troubles with the following code. At this point I'd like to see the alert but not even that is happening.
$.getJSON('demo.js',function(result){
alert(1);
$.each(result, function(i, field){
$("div").append(field + " ");
});
});
demo.js looks like:
{
"firstName": "John",
"lastName": "Doe",
"age": 25
}
That alert isn't even popping up. This is code taken from a web tutorial and it's not working for me. I'm pretty stumped. Any ideas?
Upvotes: 1
Views: 377
Reputation: 3711
For debug purpose, you can do
$.getJSON('demo.js',function(result) {
console.log(result);
}).fail(function (j, t, e) {
console.error(e);
});
But I think your problem is either invalid json or header.
Upvotes: 2
Reputation: 4304
In order to $.getJSON, you have to submit a json datatype
Using longhand $.ajax would work i believe if you were to omit datatype, but theres really no reason unless by your own restriction that demo sold be a js instead of a json file
Upvotes: 0