gpt4 book ai didi

angularjs - ionic http 发布到外部 url

转载 作者:行者123 更新时间:2023-12-04 21:09:11 25 4
gpt4 key购买 nike

我正在尝试使用 angular 向带有 Ionic 的 url 发送帖子,但我有以下响应:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. The response had HTTP status code 404.



我知道外部服务正在运行,因为我通过 ajax 对其进行了测试,并且一切正常...

在 AngularJS (Ionic) 和 Ajax 中使用的代码下方:

ionic :
var loginServiceUrl = 'http://url.com.br'; //It is not the real one
var loginServiceData = {
email: email@email.com.br
senha: 1234
};
$http.post(loginServiceUrl, loginServiceData).
then(function (res){
console.log(res);
});

Ajax :
$.ajax({
type: "POST",
url : 'http://url.com.br', //It is not the real one
data : {email: 'email@email.com.br', senha: '1234'},
success: function(result) {
$('html').text(JSON.stringify(result));
}
});

有谁知道为什么我通过 ajax 在我的本地主机上而不是通过 ionic 和本地主机获取帖子?

最佳答案

看一下这个。很好地解释了如何处理像您这样的问题--> http://blog.ionic.io/handling-cors-issues-in-ionic/

关于angularjs - ionic http 发布到外部 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38234561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com