angular.js - How to set up the post request issued by angularjs $resource in detail?
高洛峰
高洛峰 2017-05-15 16:51:40
0
2
583

Angular's service is defined like this (the loginModule is defined in another file, so it is just a reference without writing the second parameter):

angular.module('loginModule').factory('askSecCode',['$resource',
    function askSecCodeFactory($resource){
        return $resource('http://192.168.31.108:8080/retailer/user/auth',{},{crossOrigin:'Anonymous',userName:'QD100',userPass:'1234',checkCode:'1234'});
    }
]);

This is how service is used in the controller:

$scope.loginJump = function(info){
    askSecCode.save(
        {
            userName:info.staffID,
            userPass:info.password,
            checkCode:info.security
        },
        function(){
            console.log('post sent');
        }
    );
    //TODO: ??[?????????????????????][????]
    //TODO: ????????location.assign();
};

The resulting request is as follows:

And the request result is an error

I used jquery to request the same location successfully. The request details are as follows, which is indeed different from the angular request

Help: How can I make requests sent by angularjs be accepted by the backend as CORS cross-domain requests like jquery?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
迷茫

Your problem is due to the inconsistent content-type in the header. The default in jquery is application/x-www-form-urlencoded, while in angular the default is application/json. If you want angular to make the same request as jquery, just change the header of resources

洪涛

Backend settings

header('Access-Control-Allow-Origin:http://192.168.31.172:8000');
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template