Home > Web Front-end > JS Tutorial > body text

Implement ajax to obtain cross-domain data (graphic tutorial)

亚连
Release: 2018-05-21 15:52:25
Original
1749 people have browsed it

This article mainly introduces in detail how to simply implement ajax to obtain cross-domain data. It has a certain reference value. Interested friends can refer to it.

The examples in this article are shared with you. The specific code for ajax to obtain cross-domain data is for your reference. The specific content is as follows

1. Rendering

##2. Source code

<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", // 后台定义的回调函数标识符(一般默认为:callback)
        jsonpCallback: "jsonCallback", // 自定义的jsonp回调函数名称(默认为jQuery自动生成的随机函数名)
        success: function(data,status){
          console.log(data);
          console.log(status);
        },
        error: function(){
          alert(&#39;fail&#39;);
        }
      });
    }
  </script>
</head>
<body>
  <button onclick="getData(&#39;我&#39;);">百度搜索"我"</button>
</body>
</html>
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

thinkPHP ajaxMethod to achieve statistical page pv views

Ajax The concepts and advantages

Three implementation methods of

ajax

The above is the detailed content of Implement ajax to obtain cross-domain data (graphic tutorial). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!