zoukankan      html  css  js  c++  java
  • JS 跨域

    根据同源策略  浏览器会禁止跨域

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
    </head>
    <body>
    <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
        function show(data){
          console.log(data);
        }
    
    $(function(){
        // $.ajax({
        //     url: 'http://fanyi.youdao.com/openapi.do',
        //     type: 'GET',
        //     dataType: 'json',
        //     data: {
        //         'keyfrom': 'rakustrans',
        //         'key': '1506707246',
        //         'type': 'data',
        //         'doctype': 'json',
        //         'version': '1.1',
        //         'q': 'seti'
        //     },
        // }).done(function(data) {
        //     console.log(data);
        //     notif({
        //         msg: data,
        //         type: "success"
        //     });
        // }).fail(function() {
        //     console.log("error");
        // }).always(function() {
        //     console.log("complete");
        // });
    
        function show(data){
          console.log(data);
        }
        $.ajax({
          url: 'http://fanyi.youdao.com/openapi.do?keyfrom=rakustrans&key=1506707246&type=data&doctype=jsonp&callback=show&version=1.1&q=API',
          dataType: 'jsonp'
        })
        .done(function() {
          console.log("success");
        })
        .fail(function() {
          console.log("error");
        })
        .always(function() {
          console.log("complete");
        });
    
    
    });
    
    
    </script>
    </body>
    </html>
  • 相关阅读:
    calc, support, media各自的含义及用法?
    vuex有哪几种属性
    vue-router实现路由懒加载( 动态加载路由 )
    vue生命周期的理解
    vue初始化页面闪动问题
    .params和query的区别
    实现布局数据渲染以列为单位
    一. async函数
    一. includes
    十五. 对象的扩展
  • 原文地址:https://www.cnblogs.com/cart55free99/p/3802708.html
Copyright © 2011-2022 走看看