Javascript API REST JQUERY
我想使用API jquery.rest(例如),在控制台上执行任何操作。 这是我的剧本Javascript API REST JQUERY,javascript,jquery,http,Javascript,Jquery,Http,我想使用API jquery.rest(例如),在控制台上执行任何操作。 这是我的剧本 var client = new $ RESTClient ('http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139'); client.show (); 我的控制台上没有显示任何内容嗨,为什么不尝试使用jQuery内置的$.ajax()调用使用jsonp数据类型 以下是我成功的尝试: 希望这有帮助 如果您使用这个:那么看起
var client = new $ RESTClient ('http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139');
client.show ();
我的控制台上没有显示任何内容嗨,为什么不尝试使用jQuery内置的
$.ajax()
调用使用jsonp
数据类型
以下是我成功的尝试:
希望这有帮助 如果您使用这个:那么看起来您的大小写错误了
尝试:
奶昔的反应就是你想要的为了满足您的需要,我正在将您的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!");
});
什么是
RESTClient
您编写的类或库?该API不支持CORS,因此您可以仅使用javascript获取它,您需要创建服务器端代理。
var client = new $.RestClient('http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139');
client.show();
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!");
});