欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

簡(jiǎn)單實(shí)現(xiàn)ajax獲取跨域數(shù)據(jù)

 更新時(shí)間:2018年04月06日 13:30:04   作者:冷月葬殘花  
這篇文章主要為大家詳細(xì)介紹了如何簡(jiǎn)單實(shí)現(xiàn)ajax獲取跨域數(shù)據(jù)的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了ajax獲取跨域數(shù)據(jù)的具體代碼,供大家參考,具體內(nèi)容如下

1.效果圖

2.源碼

<html>
<head>
  <script type="text/javascript" src="/js/jquery.min.js"></script>
  <script type="text/javascript">
    function getData(keyword) {
      var url="https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=" +keyword;
      $.ajax({
        type: "get",
        async: false,
        url: encodeURI(url),
        dataType: "jsonp",
        jsonp: "cb", // 后臺(tái)定義的回調(diào)函數(shù)標(biāo)識(shí)符(一般默認(rèn)為:callback)
        jsonpCallback: "jsonCallback", // 自定義的jsonp回調(diào)函數(shù)名稱(默認(rèn)為jQuery自動(dòng)生成的隨機(jī)函數(shù)名)
        success: function(data,status){
          console.log(data);
          console.log(status);
        },
        error: function(){
          alert('fail');
        }
      });
    }
  </script>
</head>
<body>
  <button onclick="getData('我');">百度搜索"我"</button>
</body>
</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論