-1
我得到错误说:SyntaxError: Unexpected token ':'. Parse error."
越来越拉JSON的错误从URL
我是否做
url = 'http://api.openweathermap.org/v3/uvi/20,77/current.json?appid=c0d8761ca979157a45651a5c7f12a6be';
function getJSONP(url, success) {
var ud = '_' + +new Date,
script = document.createElement('script'),
head = document.getElementsByTagName('head')[0]
|| document.documentElement;
window[ud] = function(data) {
head.removeChild(script);
success && success(data);
};
script.src = url.replace('callback=?', 'callback=' + ud);
head.appendChild(script);
}
getJSONP(url, function(data){
console.log(data);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<html><body>
,或者如果我这样做:
url = 'http://api.openweathermap.org/v3/uvi/20,77/current.json?appid=c0d8761ca979157a45651a5c7f12a6be';
function CallURL() {
$.ajax({
url: url,
type: "GET",
dataType: "jsonp",
async: false,
success: function(msg) {
console.log(msg);
JsonpCallback(msg);
},
error: function() {
// ErrorFunction();
// break ;
}
});
}
function JsonpCallback(json) {
alert(json);
//document.getElementById('summary').innerHTML = json.result;
}
CallURL();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<html>
<body>
</body>
</html>