IE给出“错误”和“许可被拒绝”用于 AJAX 请求
我有一个正在进行 AJAX 调用(JSONP)的脚本,
$("#searchbox").autocomplete({
source: function(request, response) {
$.ajax({
url: 'http://query.yahooapis.com/v1/public/yql',
dataType: 'JSONP',
data: {
format: 'json',
q: 'select * from xml where url="http://google.com/complete/search?hl=nl&output=toolbar&q=' + encodeURIComponent(request.term) + '"'
},
success: function(data) {
if (typeof data == 'string') data = $.parseJSON(data);
response($.map(data.query.results.toplevel.CompleteSuggestion, function(item) {
return { label: item.suggestion.data, value: item.suggestion.data };
}));
}
});
},
select: function(e, ui){
},
open: function(){
doSearch($('.ui-autocomplete li:first-child a').text(), true, false);
$(".ui-autocomplete :first-child a").addClass("ui-state-hover");
$("#searchbox").focus();
return false;
},
select: function(e, ui){
$("#searchbox").autocomplete('search', ui.item.value);
},
close : function (event, ui) {
val = $("#searchbox").val();
$("#searchbox").autocomplete( "search", val );
}
});
我在 Google 上搜索过它,结果发现它是一个安全问题。因为请求(输出)来自其他域(即 Bing)。我尝试了很多事情但没有运气。 这是我的文档类型等等:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="desktop.css" media="screen" rel="stylesheet" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Asap' rel='stylesheet' type='text/css'>
<link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script>
<meta charset=utf-8 />
<script src="livesearch.js" type="text/javascript"></script>
<link href='http://fonts.googleapis.com/css?family=Loved+by+the+King' rel='stylesheet' type='text/css'>
</head>
从她开始,除了纯 HTML 就没有别的了。
I have this script which is making AJAX call (JSONP)
$("#searchbox").autocomplete({
source: function(request, response) {
$.ajax({
url: 'http://query.yahooapis.com/v1/public/yql',
dataType: 'JSONP',
data: {
format: 'json',
q: 'select * from xml where url="http://google.com/complete/search?hl=nl&output=toolbar&q=' + encodeURIComponent(request.term) + '"'
},
success: function(data) {
if (typeof data == 'string') data = $.parseJSON(data);
response($.map(data.query.results.toplevel.CompleteSuggestion, function(item) {
return { label: item.suggestion.data, value: item.suggestion.data };
}));
}
});
},
select: function(e, ui){
},
open: function(){
doSearch($('.ui-autocomplete li:first-child a').text(), true, false);
$(".ui-autocomplete :first-child a").addClass("ui-state-hover");
$("#searchbox").focus();
return false;
},
select: function(e, ui){
$("#searchbox").autocomplete('search', ui.item.value);
},
close : function (event, ui) {
val = $("#searchbox").val();
$("#searchbox").autocomplete( "search", val );
}
});
I have Googled for it and it turns out its a security problem. Because the reqeust(output) is from an other domain (which is Bing). I have tried many things but with no luck.
This is my doctype and so on:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="desktop.css" media="screen" rel="stylesheet" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Asap' rel='stylesheet' type='text/css'>
<link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script>
<meta charset=utf-8 />
<script src="livesearch.js" type="text/javascript"></script>
<link href='http://fonts.googleapis.com/css?family=Loved+by+the+King' rel='stylesheet' type='text/css'>
</head>
From her on there is nothing else but plain HTML.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非此服务确实支持
jsonp
,否则您应该这样做:jsonp
语句一起使用,Unless this service does support
jsonp
you should do this:jsonp
-statement you posted in your first post由于网络浏览器采用同源策略,XMLHttpRequest 不允许发出跨域请求。请改用
JSONP
。XMLHttpRequests are not allowed to make cross-domain requests due to the same origin policy employed by web browsers. Use
JSONP
instead.