IE给出“错误”和“许可被拒绝”用于 AJAX 请求

发布于 2025-01-02 11:14:50 字数 2587 浏览 0 评论 0原文

我有一个正在进行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

安稳善良 2025-01-09 11:14:50

除非此服务确实支持 jsonp,否则您应该这样做:

  1. 对服务器上的 php 文件进行 ajax 调用。
  2. 在您的 php 文件中,您将 cURL 与您在第一篇文章中发布的原始 jsonp 语句一起使用,
  3. 格式化查询结果并将其输出,以便 javascript 可以访问它
  4. 完成!

Unless this service does support jsonp you should do this:

  1. Make a ajax-call to a php-file on your server.
  2. In you php-file you use cURL with the original jsonp-statement you posted in your first post
  3. Format your results from the query and output it so the javascript can access it
  4. Done!
梦断已成空 2025-01-09 11:14:50

由于网络浏览器采用同源策略,XMLHttpRequest 不允许发出跨域请求。请改用 JSONP

XMLHttpRequests are not allowed to make cross-domain requests due to the same origin policy employed by web browsers. Use JSONP instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文