例子:
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>$httpAjax</title>
<script src="../../frameWork/js/angular.min.js"></script>
<script>
//创建模块
var app = angular.module('myApp',[]);
//创建控制器
//(1)请求js的时候:自己写的处理函数,callback对应的函数名,以及后台的处理函数名都要一样
//而且此时根本不用调用success()
/*app.controller('oneController',function ($scope,$http) {
$http.jsonp('test.js?callback=test');
})
function test(data) {
console.log(data);
}*/
//(2)angular用jsonp处理跨域访问
app.controller('oneController',function ($http) {
$http.jsonp('test.js?callback=JSON_CALLBACK').success(function (data) {
console.log(data);
});
})
</script>
</head>
<body ng-controller="oneController">
</body>
</html>
test.js
//test('haha');
angular.callbacks._0('hello');