IE 中不允许自动完成 AJAX 请求
下面的代码在 IE 中给我带来了问题。 IE 告诉我存在安全风险并禁止代码运行。
$("#searchbox").autocomplete({
source: function(request, response) {
$.ajax({
url: 'http://query.yahooapis.com/v1/public/streaming/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 );
}
});
我做了一些调查,结果发现这一行给了我问题: url: 'http://query.yahooapis.com/v1/public/streaming/yql',
所以我是想知道我可以替换什么或修改什么才能使其正常工作。这是一个实时版本: JsBin
The following code is giving me problems in IE. IE is telling me that there is a security risk and prohibits the code to function.
$("#searchbox").autocomplete({
source: function(request, response) {
$.ajax({
url: 'http://query.yahooapis.com/v1/public/streaming/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 done some investigation and it turns out that this line is giving me the problem: url: 'http://query.yahooapis.com/v1/public/streaming/yql',
So I was wondering with what I can replace or what to modify to make it work. Here is a live version: JsBin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这看起来可能是跨域请求,这在我的经验中是一个痛苦。
您将需要使用 XDR 调用(并非所有 IE 版本都支持),或者您将需要使用主机的反向代理...请参阅本文:http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
This looks like its maybe a Cross Domain Request, which is a pain in my experience.
You will need to use XDR calls (not supported in all IE versions), OR you will need to use a reverse proxy from your host... See this article: http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx