Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery读取json文件_Jquery_Json - Fatal编程技术网

使用jquery读取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 + '<

我正在尝试使用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 + '</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>');          
});