0

I want to use the API jquery.rest on this site(for example), I execute anything on my console. here is my script

 var client = new $ RESTClient ('http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139');
 client.show ();

nothing appears on my console

2
  • What is RESTClient a class you wrote or a library? Commented Aug 2, 2013 at 12:32
  • That API don't support CORS so you can fetch it using just javascript, you need to create server side proxy. Commented Aug 2, 2013 at 12:34

3 Answers 3

1

Hi why dont you try using the the jQuery's built in $.ajax() call using jsonp dataType? see here

here is my successfull attempt:

var URI = 'http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139';
$.ajax({url:URI,dataType:"jsonp"})
      .done(function(object){
        //now you can access your object like any other json object e.g.
        alert(object.sys.country);
      })
      .fail(function(){
        alert("oh no - something went wrong!");
      });

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

0

If you are using this : https://github.com/jpillora/jquery.rest then it looks like you have the capitalization wrong.

try:

var client = new $.RestClient('http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139');
client.show();

Comments

0

milkshake's response is what you are after. - just to suit your need , I am converting your json object into string - so you can have better idea.

  var URI = 'http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139';
    $.ajax({url:URI,dataType:"jsonp"})
        .done(function(object){
          //now you can access your object like any other json object e.g.
         alert(JSON.stringify(object));
      })
      .fail(function(){
        alert("oh no - something went wrong!");
      });

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.