AngularJS发送OPTIONS请求而不是POST

前端之家收集整理的这篇文章主要介绍了AngularJS发送OPTIONS请求而不是POST前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图将图片上传到我的S3桶.我使用AngularJS v1.2.13.
当我使用他们的文档中显示的简单情况(提交表单与动作标签)一切正常.但是,如果我想这样做,Angular的方式用ng-click Angular发送OPTIONS请求而不是POST请求.

以下是服务代码,它首先去服务器获取签名(我知道那部分是好的)然后尝试POST一切.

myServices.factory('s3',function($http) {
    var service = {};

    service.upload = function(fileName) {

        return $http(
            {
                method:"POST",url: "sign",data: { "fileName": fileName }
            }
        ).then(
            function(result) {
                // success
                //resolve the promise as the data
                var data = result.data;
                var url = "https://" + data.bucket + ".s3.amazonaws.com/";

                return $http.post(url,{
                    "key": data.key,"AWSAccessKeyId": data.awsKey,"acl": data.acl,"policy": data.policy,"signature": data.signature,"Content-Type": "image/jpeg","success_action_redirect": "http://localhost:3000/s3Uploaded"
            }).then(
            function(response) {
                // success
                console.log("s3.upload,success: ");
                console.log(response);
            },function(response) { 
                // Failed
                console.log("s3.Upload,fail: ");
                console.log(response);
            }
        );

    },function(response) { 
            // Failed
            console.log("s3.sign,fail: ");
            console.log(response);
        }
    );
};

return service;
});

我究竟做错了什么?

我不知道这些资源是否会帮助你,但这听起来像是同样的问题:

HTTP POST turns into OPTIONS

OPTIONS preflight call preceding a $http.post request

原文链接:https://www.f2er.com/angularjs/142582.html

猜你在找的Angularjs相关文章