Angular + Ionic Post请求未找到404

编程入门 行业动态 更新时间:2024-10-11 05:24:35
本文介绍了Angular + Ionic Post请求未找到404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经搜索了这个错误背后的原因,过去几个小时无法解决。希望有人遇到过同样的问题并能够帮助解决问题。

I have searched for the reason behind this error for the last couple hours unable to solve it. Hopefully someone has experienced the same issue and is able to help with a remedy.

我正在使用Ionic和Angular来创建一个简单的应用程序。我在本地使用Ionics ionic serve 命令来设置一个简单的服务器。

I am using Ionic and Angular to create a simple application. I am running locally using Ionics ionic serve command to set up a simple server.

我有一个简单的index.html页面,如下所示:

I have a simple index.html page that is as follows:

... <body data-ng-controller="AppCtrl"> <ion-header-bar class="bar-balanced"> <h1 class="title ">Hello World!</h1> </ion-header-bar> <ion-content> <h1>Some Content</h1> </ion-content> </body> ...

和一个已经多次迭代并试过的app.js文件最终的各种在线教程:

and an app.js file that has been iterated numerous times and tried various online tutorials to end up with:

var App = angular.module("App", ["ionic"]); App.controller("AppCtrl", ["$scope", "$http" , AppCtrl]); function AppCtrl($scope, $http) { $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded"; var request = $http({ method: 'post', url: 'localhost:8100/php/login.php', data: { "cat" : "henry" }, headers : {"Content-Type": 'application/x-www-form-urlencoded'} }).success(function (data, status, headers, config) { console.log(data); }).error(function (data, status, headers, config) { console.log("login.php failed"); }); };

我的问题:是我收到404 Not Found错误在我的帖子请求。但是,当我更改为get请求时,它似乎回复PHP文件就好了。它是一个简单的回声Hello World! php文件。

My problem: is that I am getting "404 Not Found" error on my post requests. However, when I change to a get request, it seems to echo back the PHP file just fine. Its a simple echo "Hello World!" php file.

此时,我们将非常感谢任何有用的信息。谢谢!

At this point, any helpful information would be greatly appreciated. Thank you!

推荐答案

我遇到了类似的问题,我这个网站帮助我理解了我的问题: http:// victorblog。 com / 2012/12/20 / make-angularjs-http-service-behave-like-jquery-ajax /

I got a similar issue and I this site helped me to understand my problem: victorblog/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/

默认情况下:

By default:

jQuery 使用内容类型传输数据: x-www-form-urlencoded。 AngularJS 使用Content-Type传输数据: application / json。

jQuery transmits data using Content-Type: x-www-form-urlencoded. AngularJS transmits data using Content-Type: application/json.

不幸的是,有些Web服务器语言,特别是PHP,不要本地反序列化。

Which unfortunately some Web server languages, notably PHP, do not unserialize natively.

我的解决方案是: 在我的.PHP中我刚刚在我的内容中做了一个JSON_DECODE

My solution was: In my .PHP I just did a JSON_DECODE in my content

$ data = json_decode(file_get_contents('php:// input'),true);

$data = json_decode(file_get_contents('php://input'), true);

更多推荐

Angular + Ionic Post请求未找到404

本文发布于:2023-10-12 04:26:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483720.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:未找到   Ionic   Angular   Post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!