久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='roZf7'></bdo><ul id='roZf7'></ul>

    1. <legend id='roZf7'><style id='roZf7'><dir id='roZf7'><q id='roZf7'></q></dir></style></legend>
      <i id='roZf7'><tr id='roZf7'><dt id='roZf7'><q id='roZf7'><span id='roZf7'><b id='roZf7'><form id='roZf7'><ins id='roZf7'></ins><ul id='roZf7'></ul><sub id='roZf7'></sub></form><legend id='roZf7'></legend><bdo id='roZf7'><pre id='roZf7'><center id='roZf7'></center></pre></bdo></b><th id='roZf7'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='roZf7'><tfoot id='roZf7'></tfoot><dl id='roZf7'><fieldset id='roZf7'></fieldset></dl></div>

        <small id='roZf7'></small><noframes id='roZf7'>

        <tfoot id='roZf7'></tfoot>

        跨站 XMLHttpRequest

        Cross-site XMLHttpRequest(跨站 XMLHttpRequest)
          <tbody id='ztZ26'></tbody>
          <bdo id='ztZ26'></bdo><ul id='ztZ26'></ul>
        • <tfoot id='ztZ26'></tfoot>

            <small id='ztZ26'></small><noframes id='ztZ26'>

                <legend id='ztZ26'><style id='ztZ26'><dir id='ztZ26'><q id='ztZ26'></q></dir></style></legend>
                  <i id='ztZ26'><tr id='ztZ26'><dt id='ztZ26'><q id='ztZ26'><span id='ztZ26'><b id='ztZ26'><form id='ztZ26'><ins id='ztZ26'></ins><ul id='ztZ26'></ul><sub id='ztZ26'></sub></form><legend id='ztZ26'></legend><bdo id='ztZ26'><pre id='ztZ26'><center id='ztZ26'></center></pre></bdo></b><th id='ztZ26'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ztZ26'><tfoot id='ztZ26'></tfoot><dl id='ztZ26'><fieldset id='ztZ26'></fieldset></dl></div>
                1. 本文介紹了跨站 XMLHttpRequest的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想提供一段 Javascript 代碼,它可以在包含它的任何網站上運行,但它總是需要在托管 Javascript 的服務器上獲取更多數據(甚至修改數據).我知道出于顯而易見的原因存在安全限制.

                  I want to provide a piece of Javascript code that will work on any website where it is included, but it always needs to get more data (or even modify data) on the server where the Javascript is hosted. I know that there are security restrictions in place for obvious reasons.

                  考慮在 xyz.com 上托管的 index.html,其中包含以下內容:

                  Consider index.html hosted on xyz.com containing the following:

                  <script type="text/javascript" src="http://abc.com/some.js"></script>
                  

                  some.js 能否使用 XMLHttpRequest 將數據發布到 abc.com?換句話說,abc.com 是否因為我們從那里加載了 Javascript 而被隱式信任?

                  Will some.js be able to use XMLHttpRequest to post data to abc.com? In other words, is abc.com implicitly trusted because we loaded Javascript from there?

                  推薦答案

                  some.js 能否使用 XMLHttpRequest 將數據發布到 abc.com?換句話說,abc.com 是否因為我們從那里加載了 Javascript 而被隱式信任?

                  Will some.js be able to use XMLHttpRequest to post data to abc.com? In other words, is abc.com implicitly trusted because we loaded Javascript from there?

                  不,因為腳本被加載到一個單獨的域中,它沒有訪問權限...

                  No, because the script is loaded on to a seperate domain it will not have access...

                  如果您信任數據源,那么 JSONP 可能是更好的選擇.JSONP 涉及將新的 SCRIPT 元素動態添加到頁面,并將 SRC 設置為另一個域,并將回調設置為查詢字符串中的參數.例如:

                  If you trust the data source then maybe JSONP would be the better option. JSONP involves dynamically adding new SCRIPT elements to the page with the SRC set to another domain, with a callback set as a parameter in the query string. For example:

                  function getJSON(URL,success){
                      var ud = 'json'+(Math.random()*100).toString().replace(/./g,'');
                      window[ud]= function(o){
                          success&&success(o);
                      };
                      document.getElementsByTagName('body')[0].appendChild((function(){
                          var s = document.createElement('script');
                          s.type = 'text/javascript';
                          s.src = URL.replace('callback=?','callback='+ud);
                          return s;
                      })());
                  }
                  
                  getJSON('http://YOUR-DOMAIN.com/script.php?dataName=john&dataAge=99&callback=?',function(data){
                      var success = data.flag === 'successful';
                      if(success) {
                          alert('The POST to abc.com WORKED SUCCESSFULLY');
                      }
                  });
                  

                  因此,您需要托管自己的腳本,該腳本可以使用 PHP/CURL 發布到 abc.com 域,然后以 JSONP 格式輸出響應:

                  So, you'll need to host your own script which could use PHP/CURL to post to the abc.com domain and then will output the response in JSONP format:

                  我不太擅長 PHP,但可能是這樣的:

                  I'm not too great with PHP, but maybe something like this:

                  <?php
                      /* Grab the variables */
                      $postURL = $_GET['posturl'];
                      $postData['name'] = $_GET['dataName'];
                      $postData['age'] = $_GET['dataAge'];
                  
                      /* Here, POST to abc.com */
                      /* MORE INFO: http://uk3.php.net/curl & http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html */
                  
                      /* Fake data (just for this example:) */
                      $postResponse = 'blahblahblah';
                      $postSuccess = TRUE;
                  
                      /* Once you've done that, you can output a JSONP response */
                      /* Remember JSON format == 'JavaScript Object Notation' - e.g. {'foo':{'bar':'foo'}} */
                      echo $_GET['callback'] . '({';
                      echo "'flag':' . $postSuccess . ',";
                      echo "'response':' . $postResponse . '})";
                  
                  ?>
                  

                  因此,您可以控制的服務器將充當客戶端和 abc.com 之間的媒介,您將以 JSON 格式將響應發送回客戶端,以便 JavaScript 可以理解和使用它...

                  So, your server, which you have control over, will act as a medium between the client and abc.com, you'll send the response back to the client in JSON format so it can be understood and used by the JavaScript...

                  這篇關于跨站 XMLHttpRequest的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)

                    • <i id='f3yqu'><tr id='f3yqu'><dt id='f3yqu'><q id='f3yqu'><span id='f3yqu'><b id='f3yqu'><form id='f3yqu'><ins id='f3yqu'></ins><ul id='f3yqu'></ul><sub id='f3yqu'></sub></form><legend id='f3yqu'></legend><bdo id='f3yqu'><pre id='f3yqu'><center id='f3yqu'></center></pre></bdo></b><th id='f3yqu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='f3yqu'><tfoot id='f3yqu'></tfoot><dl id='f3yqu'><fieldset id='f3yqu'></fieldset></dl></div>

                      <tfoot id='f3yqu'></tfoot>

                      <small id='f3yqu'></small><noframes id='f3yqu'>

                          <bdo id='f3yqu'></bdo><ul id='f3yqu'></ul>

                              <tbody id='f3yqu'></tbody>
                            <legend id='f3yqu'><style id='f3yqu'><dir id='f3yqu'><q id='f3yqu'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 一区在线播放 | 欧美精品一区二区三区四区五区 | 成人久久 | 中文字幕欧美一区二区 | 在线看片网站 | 日韩在线视频一区 | 亚洲经典一区 | 日本不卡免费新一二三区 | 中文字幕蜜臀av | 夜夜草导航 | 日本不卡一区二区三区在线观看 | 欧美精品久久久 | 午夜精品久久久久久久99黑人 | 黄色片免费在线观看 | 国产精品亚洲二区 | 毛片免费看 | 日本不卡一区 | 国产成人综合久久 | 日韩视频1 | 日韩欧美国产不卡 | 欧美精产国品一二三区 | 天天干狠狠干 | 欧美a级成人淫片免费看 | 波多野结衣一区二区 | 这里只有精品999 | 成人在线观看免费 | 在线观看av网站永久 | 午夜影视免费片在线观看 | 91视频入口 | 91久操视频 | 日韩a视频| 99re在线| 综合久久网 | 精品国产区 | 午夜激情在线视频 | 久久久999成人 | 久久国产精品一区二区三区 | 91毛片网 | 国产精品久久久久久久7777 | 精品中文字幕一区二区三区 | 精品国产欧美 |