javascript AngularJS http.post() 返回 404

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20751208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 19:12:53  来源:igfitidea点击:

AngularJS http.post() returns 404

javascriptangularjscordova

提问by JocisPR

Hi and merry christmas to you all.

大家好,圣诞快乐。

I am working with a Phonegap AngularJS App. I am trying to make an http Post but I it returns an 404 error. I tried the POST using jquery 1.10.2 and it works. I have been days in this and it is the last part to finish coding the app.

我正在使用 Phonegap AngularJS 应用程序。我正在尝试制作一个 http 帖子,但它返回 404 错误。我使用 jquery 1.10.2 尝试了 POST 并且它有效。我已经在这方面呆了几天,这是完成应用程序编码的最后一部分。

I have tried different versions of the request with no success.

我尝试了不同版本的请求,但没有成功。

Here is the code

这是代码

$scope.sendMail = function (user){ 
    console.log('sendmaul');


$http.post('https://cloud/email.aspx',
   {
        user: user.email,
        pass: user.password,
        to:user.recipient,
        subject:'Test',
        message:'My Message'
    }
    )
.success(function (data, status, headers, config){
        console.log('success');

})
.error(function (data,status,headers,config){
        console.log(data + status + config);
    });
}

I have read in many places that I need to add on a angular.module the following code as .config

我在很多地方都读过我需要在 angular.module 上添加以下代码作为 .config

$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];

I added that code on controller.js but I don't see difference on behavior in my app. I also have many http.get() request that work really well.

我在 controller.js 上添加了该代码,但在我的应用程序中没有看到行为差异。我也有很多 http.get() 请求非常有效。

--EDIT--

- 编辑 -

https://cloud.email.aspxis not a real site.

https://cloud.email.aspx不是真正的网站。

回答by JocisPR

Solved my problem.

解决了我的问题。

After adding CORS and some Origins Exceptions on server side. I tried my code and got Success and 200 status response but the web service did nothing. After reading this other stackoverflow postI found out that Angularjs post data different from jquery so a normal POST read on the web service would not work. That post have a link to this sitewhich explain in more detail my issue and it has some code for to send data the same way jquery does.

在服务器端添加 CORS 和一些 Origins Exceptions 后。我尝试了我的代码并获得了 Success 和 200 状态响应,但 Web 服务什么也没做。阅读完这篇其他stackoverflow 帖子后,我发现 Angularjs 发布的数据与 jquery 不同,因此在 Web 服务上读取正常的 POST 数据将不起作用。那个帖子有一个指向这个站点的链接,它更详细地解释了我的问题,它有一些代码可以像 jquery 一样发送数据。

I hope this help someone

我希望这有助于某人