为什么已经用了jsonp了,还是存在跨域问题?!!求大神指教啊!!1
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>必应练习</title>
<script type="text/javascript" src="G:\sublime\jquery\jquery-2.1.1.min.js"></script>
<style type="text/css">
*{margin:0;padding:0;}
body{background-color: #333;}
#main{background-image: url(river.jpg);width:1228px;height:690px;margin: 0 auto;position: relative;}
#search{position:absolute;top:150px;left: 200px; }
.img{float: left;margin-right:18px;margin-top: -4px;}
.form{float: left;background-color: #fff;padding: 5px;}
.search-text{height:25px;line-height: 25px;width: 350px;border:0;outline: none;float: left;}
/*outline:none外框点击时高亮取消*/
.search-submit{border: 0;background-image: url(search-button.png);width:29px;height:29px;float: left;}
/*注意!!要想容器里在同一行高低不一致的两者同样高低,可以用float:left*/
#tip{
background-color:#fff;
width:389px;
position: absolute;
top:189px;
left:325px;
visibility: hidden;
}
#tip ul{
list-style: none;
}
#tip ul li a{
display: block;
padding:5px;
font-size: 15px;
color: #777;
text-decoration: none;
}
#tip ul li:hover{
background-color:#CCC;
text-decoration: underline;
}
/* 如果想用focus,则必须是在该容器下的 */
</style>
</head>
<body>
<div id="main">
<div id="search">
<img src="logo.png" class="img">
<form class="form">
<input type="text" class="search-text">
<input type="submit" class="search-submit" value="">
<!-- input中是无法插入img的 -->
</form>
</div>
<div id="tip">
<ul id="search-list">
<li><a href="#">搜索内容</a></li>
<li><a href="#">搜索内容</a></li>
<li><a href="#">搜索内容</a></li>
</ul>
</div>
</div>
<script type="text/javascript">
$(function(){
$(".search-text").bind({'focus':function(){
$('#tip').css({'visibility': 'visible'});
var searchresult=$(this).val();
$.ajax({
type: "GET",
url: "http://api.bing.com/qsonhs.aspx?q=" + searchresult,
dataType: "jsonp",
jsonp: "callback",
success: function(data) {
var data=data.AS.Results[0].Suggests;
if (data.success) {
$.each(data,function(index){
$("#search-list").append('<li><a href="#">'+data.eq(index)+'</a></li>')
});
} else {
$("#searchResult").html("出现错误:" + data.msg);
}
},
error: function(jqXHR){
alert("发生错误:" + jqXHR.status);
}
});
/*$.get('http://api.bing.com/qsonhs.aspx?q='+searchresult,function(data){
var data=data.AS.Results[0].Suggests;//取到的是一个数组
$.each(data,function(index){
$("#search-list").append('<li><a href="#">'+data.eq(index)+'</a></li>')
});
},'json');//data为服务器返回的值
*/
},'blur':function(){
$('#tip').css({'visibility': 'hidden'});}
});
});
</script>
</body>
</html>