标签:跨域 html ring col ram ext jquery java test
实现跨域访问主要通过src属性进行的,这不是一种标准的模式,但是确实解决了需求问题。
客户端:
<script>
var App = angular.module(‘App‘, []);
App.controller(‘ctl‘, [‘$scope‘, ‘$http‘, function ($scope, $http) {
$http({
url: ‘test.ashx?callback=JSON_CALLBACK‘,
method: ‘jsonp‘ // 采用JSONP方式
}).success(function (info) {
console.log(info);
});
}]);
</script>
<body ng-app="App" ng-controller="ctl">
</body>
服务端:
context.Response.ContentType = "text/plain"; string strJson = "[{\"Name\": \"wqx\", \"Age\": 12, \"Sex\": \"男\"}, {\"Name\": \"wqx\", \"Age\": 12, \"Sex\": \"男\"}]"; string callback = context.Request.Params["callback"]; context.Response.Write(callback + "(" + strJson + ")");
参考:AngularJs最简单解决跨域问题案例、Ajax跨域访问、跨域访问Jquery实现
标签:跨域 html ring col ram ext jquery java test
原文地址:http://www.cnblogs.com/wuqiuxue/p/7747443.html