使用jquery读取json文件
我正在尝试使用jquery中的getJSON函数读取json文件,我以前没有这样做过,我只是想让数据显示在我的网页上 这是我的密码使用jquery读取json文件,jquery,json,Jquery,Json,我正在尝试使用jquery中的getJSON函数读取json文件,我以前没有这样做过,我只是想让数据显示在我的网页上 这是我的密码 var url = "http://api.openweathermap.org/data/2.5/forecast?lat=35&lon=139&callback=?" ; $.getJSON(url, function(res) { $('#result').html('<p>lon: ' + res.lon + '<
var url = "http://api.openweathermap.org/data/2.5/forecast?lat=35&lon=139&callback=?" ;
$.getJSON(url, function(res) {
$('#result').html('<p>lon: ' + res.lon + '</p>');
那将是
city.coord.lon
:
var url = "http://api.openweathermap.org/data/2.5/forecast?lat=35&lon=139&callback=?" ;
$.getJSON(url, function(res) {
$('#result').html('<p>lon: ' + res.city.coord.lon + '</p>');
});
var url=”http://api.openweathermap.org/data/2.5/forecast?lat=35&lon=139&callback=?" ;
$.getJSON(url,函数(res){
$('#result').html('lon:'+res.city.coord.lon+'');
});
以下URL:
?
在JSON输出前添加一个?
如果从URL字符串中删除
回调
参数。您应该能够读取JSON对象 当您尝试加载CORS时,是否会出现CORS错误?如果是不使用CORSworks的跨域请求,则不会,但城市pat的意思是什么?我在json文件中看不到它?然后您没有仔细查看,因为它就在那里。示例与URI不一样
var url = "http://api.openweathermap.org/data/2.5/forecast?lat=35&lon=139&callback=?" ;
$.getJSON(url, function(res) {
$('#result').html('<p>lon: ' + res.city.coord.lon + '</p>');
});