我正在尝试获取基本的JSONP查询:
<html>
<head>
<script type="text/javascript" src="js/jquery1.js"></script>
<script>
$(document).ready(function(){
$.ajax({
url: 'http://www.bing.com/',
dataType: 'jsonp',
success: function(dataWeGotViaJsonp){
var text = '';
var len = dataWeGotViaJsonp.length;
$('#text').html(len);
}
});
})
</script>
</head>
<body>
<div id = 'text'></div>
</body>
</html>
我正在使用IE8和jquery v1.11.3
Syntax error ?callback=jQuery111309915726215071462_1436849961686&_=1436849961687, line 1 character 1
这是什么回调?它来自哪里?
如果我将网址更改为“https://www.bing.com/search?q=hello+world”
我明白了:
Syntax error search?q=hello+world&callback=jQuery11130544191867791898_1436850255384&_=1436850255385, line 1 character 1
答案 0 :(得分:0)
<html>
<head>
<script type="text/javascript" src="js/jquery1.js"></script>
<script>
$(document).ready(function(event){
if (event.preventDefault) {
event.preventDefault();
}
else {
event.returnValue = false;
}
$.ajax({
url: 'http://www.bing.com/',
dataType: 'jsonp',
success: function(dataWeGotViaJsonp){
var text = '';
var len = dataWeGotViaJsonp.length;
$('#text').html(len);
}
});
})
</script>
</head>
<body>
<div id = 'text'></div>
</body>
</html>
//使用event.preventDefault。
答案 1 :(得分:0)
将dataType: 'jsonp'
更改为dataType: 'text'