IE中不允许自动完成AJAX请求

时间:2012-02-06 14:54:21

标签: jquery ajax autocomplete jsonp

以下代码在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

1 个答案:

答案 0 :(得分:2)

这可能是一个跨域请求,这是我的经历中的痛苦。

您需要使用XDR调用(并非所有IE版本都支持),或者您需要使用主机的反向代理...请参阅此文章:http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx

相关问题