【问题标题】:I can't upload my files using angularjs?我无法使用 angularjs 上传我的文件?
【发布时间】:2016-06-02 12:17:47
【问题描述】:
            $scope.uploadFiles = function () {
             //debugger;
            var request = {
                method: 'POST',
                url: 'http://localhost/upload/',
                data: formdata,
                headers: {
                    'Content-Type': undefined
                }
            };

            // SEND THE FILES.
            $http(request)
                .success(function (d) {
                    alert(d);
                })
                .error(function () {
                });
        }

我正在进入控制台窗口,例如 XMLHttpRequest 无法加载 http://localhost/upload/。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'http://localhost:55555' 不允许访问。响应的 HTTP 状态代码为 405。

【问题讨论】:

标签: angularjs file-upload http-post image-uploading


【解决方案1】:

如果我理解正确,应用程序正在http://localhost:55555 运行,而您正尝试向http://localhost/upload/ 发送POST 请求(这实际上是指http://localhost:80/upload/)。您的浏览器不允许您这样做,因为 http://localhost:80/http://localhost:55555/ 是不同的来源

也许你的意思是说http://localhost:55555/upload/?这将解决您的问题。

否则您需要disable CORS in your browser 或在您的服务器中添加'Access-Control-Allow-Origin: * 标头http://localhost:80/

【讨论】:

  • 谢谢....我也试过localhost:55555/upload,但遇到了同样的问题。我会尝试'Access-Control-Allow-Origin:*否则我需要写入服务以使用C#上传图像或我应该使用一些upload.php来移动。
猜你喜欢
  • 1970-01-01
  • 2020-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-25
相关资源
最近更新 更多