worldweatheronline API响应错误
worldweatheronline API response error
我正在尝试从'worldweatheronline'中使用$http调用天气信息:
this.testApi = function(coords) {
var deferred = $q.defer();
$http.jsonp(API_ROOTS + '?key=9834687w634087623eg8932te&q=' + coords.latitude + ',' + coords.longitude + '&cc=yes&includeLocation=yes&format=json')
.then(function(response) {
deferred.resolve(response.current_condition);
console.log(response.current_condition);
}, function(error) {
deferred.reject(error);
}
);
return deferred.promise;
};
和控制器:
$scope.updateLocalWeather = function() {
$geolocation.get().then(
function(position) {
$weather.testApi(position.coords).then(
function(weather) {
$scope.localWeather = weather;
$ionicSlideBoxDelegate.update();
}
);
}
);
};
,从控制台中显示一个错误:
Uncaught SyntaxError: Unexpected token :
,但是当我输入console.log:
时,响应通过了{ "data": { "current_condition": [ {"cloudcover": "0", "FeelsLikeC": "11", "FeelsLikeF": "51", "humidity": "42", "observation_time": "07:29 AM", "precipMM": "0.0", "pressure": "1029", "temp_C": "11", "temp_F": "51", "visibility": "10", "weatherCode": "113", "weatherDesc": [ {"value": "Sunny" } ], "weatherIconUrl": [ {"value": "http:'/'/cdn.worldweatheronline.net'/images'/wsymbols01_png_64'/wsymbol_0001_sunny.png" } ], "winddir16Point": "SW", "winddirDegree": "235", "windspeedKmph": "4", "windspeedMiles": "2" } ], "nearest_area": [ { "areaName": [ {"value": "Randjesfontein" } ], "country": [ {"value": "South Africa" } ], "latitude": "-25.952", "longitude": "28.143", "population": "0", "region": [ {"value": "Gauteng" } ], "weatherUrl": [ {"value": "http:'/'/www.worldweatheronline.com'/v2'/weather.aspx?q=-25.9484274,28.1395815" } ] } ], "request": [ {"query": "Lat -25.95 and Lon 28.14", "type": "LatLon" } ], "weather": [ { "astronomy": [ {"moonrise": "09:08 PM", "moonset": "08:47 AM", "sunrise": "06:45 AM", "sunset": "05:43 PM" } ], "date": "2015-08-03", "hourly": [ {"chanceoffog": "0", "chanceoffrost": "0", "chanceofhightemp": "0", "chanceofovercast": "0", "chanceofrain": "0", "chanceofremdry": "0", "chanceofsnow": "0", "chanceofsunshine": "100", "chanceofthunder": "0", "chanceofwindy": "0", "cloudcover": "0", "DewPointC": "-3", "DewPointF": "26", "FeelsLikeC": "9", "FeelsLikeF": "48", "HeatIndexC": "9", "HeatIndexF": "47", "humidity": "43", "precipMM": "0.0", "pressure": "1028", "tempC": "9", "tempF": "47", "time": "200", "visibility": "10", "weatherCode": "113", "weatherDesc": [ {"value": "Clear" } ]}
真的不知道我在这里做错了什么。
您可以解析JSON以获得更好的结果:
$scope.localWeather = JSON.parse(weather);
但是我用json lint检查了你的json输出,它说json是错误的。你能检查在开发控制台,如果相同的JSON来自天气服务作为你的输出?如果是,那么这是api的问题,你不能做任何事情。
Gah犯了一个愚蠢的错误,我没有考虑这个问题足够长的时间…发生错误是因为我忘记将'callback=JSON_CALLBACK'
添加到jsonp呼叫的末尾…如果对其他人有帮助,我就把这个答案留在这里。
相关文章:
- 有没有任何方法可以从javascript进行跨域请求,并访问它可能生成的错误响应类型(401404等)
- 来自next()的Later.js错误响应
- 错误响应上的X-Frame-Options标头
- 无法将节点邮件程序错误响应从节点.js发送到角度.js
- 如何禁用基于 ajax 错误响应的元素
- 无法让模拟后端返回错误响应
- iOS Firefox XMLHttpRequest 错误响应
- 错误:调用 waitForCondition 时错误响应状态:13
- 添加对 jquery .submit() 的回调以读取上传的错误响应
- 为什么我的FB.api请求总是产生错误响应
- 如何在Jquery POST中获得HTTP错误响应代码?
- Javascript在读取cakephp发送的json服务器错误响应后表示未定义
- 如何在Angular上静默http错误响应
- 如何从PHP创建jqGrid JSON错误响应,然后使用jqGrid javascript对其进行响应?
- Javascript http get success函数捕获错误响应
- 在rails控制器中发回ajax错误响应
- 身份工具箱不工作-错误代码:IDP的错误响应
- 铁形式的错误响应体
- 如何在Ajax中获得错误响应
- 如何在ember js操作中获得龙卷风错误响应