For this cors cross-domain resource, the request using jquery is successful.
(The commented out code below is successful)
//var url = "http://test.shenmawo.com.cn/wechat/huodong/h22/giveGift";
//
//$.ajax({
// type : 'post',
// url : url,
// data : {
//
// },
// dataType : "json",
// success : function(data, status) {
// $scope.prize = data;
// },
// error : function(data, status, e) {
// console.log("系统异常" + e);
// }
//});
But $http.post of angularjs is unsuccessful:
$http
.post('http://test.shenmawo.com.cn/wechat/huodong/h22/giveGift', {})
.success(function(data){
$scope.prize = data;
})
.error(function(err){
alert(err);
});
Using $http([Object]) also fails:
//$http({
// url:'http://test.shenmawo.com.cn/wechat/huodong/h22/giveGift',
// method:'POST',
// data: {},
// withCredentials:true,
// success: function(data){
// $scope.prize = data;
// },
// err:function(err){
// alert(err);
// }
//});
In addition, I also added the configuration according to the searched requirements:
angular.module('zil',['ngRoute'])
.config(['$routeProvider', '$httpProvider',function($routeProvider, $httpProvider){
$httpProvider.defaults.useXDomain = true;//添加的配置
$routeProvider
.when('/',{……})
.when('/game',{
templateUrl:XXX,
controller:function(){
/*上面所有跨域请求的代码都位于这个位置*/
}
});
How can I use angularjs to make cross-domain requests?
The method I just found, the speed test was successful