我无法通过 POST 方法从 angularjs 向 php 发送请求
I can't send a request by POST method from angularjs to php
我正在尝试构建小型应用程序。它包含文本区域和下面的按钮面板,当我在此文本区域中输入第一个字母时,将显示该面板。我不得不使用 isButtonVisible() 方法。它工作正常。当我单击"发送"带有数据的请求时,问题就开始了.php方法是 POST 脚本(这是我的任务重点,它必须是 send() 方法)。请求完成后,脚本应显示带有"数据已保存"的 JavaScript alert()。
我的 angularjs 脚本(ng-controller.js)
如下所示:
angular.module("Textarea", []).controller("TextAreaCtrl", TextAreaCtrl);
function TextAreaCtrl($scope, $http)
{
'use strict';
$scope.success = false;
$scope.httpError = false;
this.isButtonVisible = function()
{
return $scope.text;
};
this.send = function ()
{
var data = $scope.text;
if(!data)
return false;
$http.post('data.php', data)
.success(function (data)
{
$scope.success = true;
})
.error(function (data)
{
$scope.httpError = true;
});
};
};
您必须在控制器中定义"$http"的使用,然后才能在函数中使用它。
angular.module("Textarea", []).controller("TextAreaCtrl", ['$scope', '$http', function($scope, $http) {
$scope.orderList = function() {
$http.post('http://example.com').
success(function(data) {
$scope.data = data;
}).
error(function(data, status) {
console.log(data);
console.log(status);
});
};
}];
相关文章:
- AngularJS JSON not arriving php
- AngularJS+PHP.登录面板
- 无法将json值从angularjs发布到php
- 将php表转换为angularjs javascript方法
- 使用AngularJs,尝试通过Google App Engine上的PHP使用HTML联系我们表单发送电子邮件
- AngularJS工厂调用PHP,然后返回AngularJS
- 如何使用Angularjs以PHP方式提交表单
- Angularjs-使用php上传文件
- 我可以't使用AngularJS读取用PHP创建的Cookie
- AngularJS:在ng-reeat中从php输出数组(带键)
- Angularjs和服务器端返回值(PHP)
- AngularJS将对象作为PHP的数组发送
- AngularJS无法从PHP获取HTTP标头
- 动态路由PHP&AngularJS
- 将JSON从PHP控制器传递到AngularJS控制器的最佳方式
- 如何处理php(Laravel-api)和javascript(AngularJS)之间的日期时间
- AngularJS与我的PHP API:获得值的工厂(async:false need alternative)
- 奇怪的行为 AngularJS & PHP
- AngularJS, PHP and json_decode
- Angularjs PHP $http和在控制器中填充$scope的数据