2

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?

2

2 Answers 2

4

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);
   }
});
Sign up to request clarification or add additional context in comments.

Comments

2

you can check it here one way to do this - Consume Service Jquery Json

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.