发布
我正在使用PHP中的OOPS,我想使用AngularJS向特定方法发布数据,我搜索了许多链接和网站,我没有找到任何解决方案,任何人都可以解决我的问题,谢谢。
这是我的JS脚本
<script type="text/javascript">
function FrmController($scope, $http) {
$scope.errors = [];
$scope.msgs = [];
$scope.SignUp = function() {
$scope.errors.splice(0, $scope.errors.length); // remove all error messages
$scope.msgs.splice(0, $scope.msgs.length);
$http.post('post_es.php', {'uname': 'testName', 'pswd': 'testPass', 'email': 'testEmail'}
).success(function(data, status, headers, config) {
if (data.msg != '')
{
$scope.msgs.push(data.msg);
}
else
{
$scope.errors.push(data.error);
}
}).error(function(data, status) { // called asynchronously
if an error occurs
// or server returns response with an error status.
$scope.errors.push(status);
});
}
}
</script>
这是php
<?php
class sampleTest {
public function firstMethod(){
$data = json_decode(file_get_contents("php://input"));
$usrname = mysql_real_escape_string($data->uname);
$upswd = mysql_real_escape_string($data->pswd);
$uemail = mysql_real_escape_string($data->email);
}
}
是否可以使用帖子/获取特定方法
您必须首先声明应用程序,然后声明您的控制器:
var app=angular.module("app",[]);
app.controller("myCtrl",function FrmController($scope, $http) {
$scope.errors = [];
$scope.msgs = [];
$scope.SignUp = function() {
$scope.errors.splice(0, $scope.errors.length); // remove all error messages
$scope.msgs.splice(0, $scope.msgs.length);
$http.post('post_es.php', {'uname': 'testName', 'pswd': 'testPass', 'email': 'testEmail'}
).success(function(data, status, headers, config) {
if (data.msg != '')
{
$scope.msgs.push(data.msg);
}
else
{
$scope.errors.push(data.error);
}
}).error(function(data, status) { // called asynchronously
if an error occurs
// or server returns response with an error status.
$scope.errors.push(status);
});
}
});
您必须通过NG-APP和NG-Controller指令链接您的应用程序和控制器:https://docs.angularjs.org/api/ng/directive/ngcontroller