Reputation: 2670
I am requesting a JSON data from a url but its giving error as
GET http://localhost:10560/[object%20Object] 404 (Not Found)
var mydata;
$.getJSON({
url: 'http://free.worldweatheronline.com/feed/weather.ashx?q=City,Country&callback=?&format=json&num_of_days=2&key=1111111111111111',
dataType: 'json',
success: function (data) {
mydata = data;
console.log(mydata);
}
});
How to get the json file and parse it?
Upvotes: 2
Views: 8802
Reputation: 740
you can check it here one way to do this - Consume Service Jquery Json
Upvotes: 2
Reputation: 2517
Your usage of jQuery.getJSON() is incorrect, docs: http://api.jquery.com/jQuery.getJSON/
Use either:
var mydata;
$.getJSON("http://free.worldweatheronline.com/feed/weather.ashx?q=City,Country&callback=?&format=json&num_of_days=2&key=1111111111111111",function(data){
console.log(data)
})
OR:
var mydata;
$.ajax({
url: 'http://free.worldweatheronline.com/feed/weather.ashx?q=City,Country&callback=?&format=json&num_of_days=2&key=1111111111111111',
dataType: 'jsonp',
success: function (data) {
mydata = data;
console.log(mydata);
}
});
Upvotes: 4