zoukankan      html  css  js  c++  java
  • 跨域的案例 以百度接口/手写接口为例,还有jQuery写法

      仅在js部分输入即可

      百度接口的案例    

      <script>
        function fn(data){
          console.log(data)
      }
      </script>
      <script src="https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=b&json=1&p=3&sid=1464_21092_18559_28607_28585_26350_28518_28627_20718&req=2&csor=1&cb=fn"></script>

      自己写的接口案例

      <script>

        function fn(data){

          console.log(data)

        }
      </script>
      <script src="01.js"></script>
      在自己写个js文件,文件名为01.js内容如下

      fn([
        {"name":"zhang"},
        {"name":"lisi"}
      ])

      jQuery中跨域获取内容的写法百度接口的案例

      <script>
        $(function(){
          $.ajax({
            type:"get",
            url:"https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su",
            async:true,
            data:{wd:"b"},
            dataType:"jsonp",
            jsonp:"cb",
            success:function(data){
              console.log(data)
            }
          });
        })
      </script>

      jQuery跨域解决自己写接口的方法

      <script>
        $(function(){
          $.ajax({
            type:"get",
            url:"http://172.16.29.30:8088/get/%E4%BC%A0%E5%8F%82%E7%9A%84%E5%8A%9F%E8%83%BD.txt",              //将服务器的数据放在页面上
            async:true,
            dataType:"jsonp",
            jsonpCallback:"fn",
            success:function(data){
              console.log(data)
            }
          });
        })
      </script>

      服务器的数据的文件名为    传参的功能.txt    (瞎起的)

      里面的内容为

      fn("hahahahaha");     (参数一定要指定数据类型,不然会报错)

  • 相关阅读:
    错误:The columns and the margins do not fit the page width.
    jasperreport使用动态jason数据源
    DynamicReport使用XML数据源+ireport的.jxml文件作为模板
    Report bands中文版
    iReport 使用json 数据源
    bat设置java环境变量
    解决DynamicReports中含有中文pdf版本不显示
    vba实现excel二级联动多选功能
    打字游戏 C语言
    fpga 任意分频 奇偶数 分频
  • 原文地址:https://www.cnblogs.com/shangjun6/p/10512633.html
Copyright © 2011-2022 走看看