API REST JQUERY

API REST JQUERY

本文关键字:JQUERY REST API      更新时间:2023-09-26

我想在这个站点上使用API jquery.rest(例如),我在控制台上执行任何操作。这是我的脚本

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

我的控制台上没有显示任何内容

嗨,为什么不尝试使用jsonp dataType使用jQuery的内置$.ajax()调用?参见此处

这是我成功的尝试:

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!");
      });

希望这能有所帮助!

如果您使用的是:https://github.com/jpillora/jquery.rest然后看起来你的大写错误了。

尝试:

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

奶昔的反应就是你想要的。-为了满足您的需要,我正在将您的json对象转换为字符串,这样您就可以有更好的想法。

  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!");
      });