AngularJS $http跨域

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="UTF-8">  
    <title>AngularJS $http跨域</title>  
</head>  
<body ng-app="App">  
    <div ng-controller="DemoController"></div>  
    <script>           
        function fn(arg) {  
  
            console.log(arg);  
  
            document.write('111');  
  
        }  
    </script>  
      
    <!-- <script src="./jsonp.php?callback=fn"></script> -->  
  
    <script src="./libs/angular.min.js"></script>  
    <script src="./libs/jquery.min.js"></script>  
    <script>  
          
        // 1、JSONP 跟Ajax 没有关系  
        // 2、$.ajax({  
  
        // });  
  
        // 3、$.ajax({  
            // url: 'example.php',  
            // type: 'post',  
            // dataType: 'jsonp'  
        // })  
  
        // var script = createElement('script');  
        // script.src = url;  
        // var head = document.querySelector('head');  
        // head.appendChild(script);  
        //   
  
        // $.ajax({  
        //  url: 'jsonp.php',  
        //  dataType: 'jsonp'  
        // });  
  
        var App = angular.module('App', []);  
  
        App.controller('DemoController', ['$http', '$scope', function ($http, $scope) {  
  
            $http({  
                url: 'jsonp.php?a=JSON_CALLBACK',  
                method: 'jsonp' // 采用JSONP方式  
            }).success(function (info) {  
                console.log(info);  
            });  
  
        }]);  
  
    </script>  
</body>  
</html>

欢迎分享本文,转载请保留出处:前端ABC » AngularJS $http跨域

分享到:更多 ()

发表评论 0