Пожалуйста, помогите мне. Я новичок в вызове ajax из json, я мог бы получить данные от json, пожалуйста, посмотрите из ниже кода.JQuery Ajax call from json get error
Можно ли позвонить с локального сервера, как его работали,
Пожалуйста, дайте Битый ясную картину
В хромированной ошибке консоли:
XMLHttpRequest cannot load http://api.openweathermap.org/data/2.5/weather?q=%2C. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8012' is therefore not allowed access. The response had HTTP status code 401.
код:
<!DOCTYPE html>
<html>
<script src="http://localhost:8012/js/jquery.min.js"></script>
<body>
<div> city : <input type="text" id="txtCity"></div><br/>
<div> Country : <input type="text" id="txtCountry"></div><br/>
<input type="button" value="Get weather" id="getWeather">
<div id="#resultDiv"></div>
<script>
$(document).ready(function() {
$("#getWeather").click(function() {
var requestData = $("#txtCity").val() + ',' + $("#txtCountry").val();
var resultElement = $("#resultDiv");
$.ajax({
url: 'http://api.openweathermap.org/data/2.5/weather',
method: 'get',
data: {
q: requestData
},
dataType: 'json',
success: function(data) {
resultElement.html('weather: ' + data.weather[0].main + '<br/>' +
'Description: ' + data.weather[0].description);
}
});
//alert("test");
});
});
</script>
</body>
</html>
столько раз задал этот вопрос. проблема cors. –
http://stackoverflow.com/questions/5750696/how-to-get-a-cross-origin-resource-sharing-cors-post-request-working check –
использовать jsonp вместо json и разрешать cors. –