Angularjs 使用angular和php连接到数据库 var-app=angular.module(“myapp”,[]); app.controller(“usercontroller”,函数($scope,$http){ $scope.insertData=函数(){ $http.post( “insert.php”, {'yourName':$scope.yourName'lstName':$scope.lstName, 'passwrd':$scope.passwrd})。成功(函数(数据){ 警报(数据); }); } });
我有这段代码,控制台返回一个错误,上面写着“成功不起作用”如何修复它?使用Angularjs 使用angular和php连接到数据库 var-app=angular.module(“myapp”,[]); app.controller(“usercontroller”,函数($scope,$http){ $scope.insertData=函数(){ $http.post( “insert.php”, {'yourName':$scope.yourName'lstName':$scope.lstName, 'passwrd':$scope.passwrd})。成功(函数(数据){ 警报(数据); }); } });,angularjs,Angularjs,我有这段代码,控制台返回一个错误,上面写着“成功不起作用”如何修复它?使用,然后使用而不是成功 <script> var app = angular.module("myapp",[]); app.controller("usercontroller",function($scope,$http){ $scope.insertData = function(){ $http.post( "insert.php", {'yourName':$scope.y
,然后使用而不是成功
<script>
var app = angular.module("myapp",[]);
app.controller("usercontroller",function($scope,$http){
$scope.insertData = function(){
$http.post(
"insert.php",
{'yourName':$scope.yourName, 'lstName':$scope.lstName,
'passwrd':$scope.passwrd}).success(function(data){
alert(data);
});
}
});
我认为你应该这样做
html
.success
已折旧,请使用。然后使用。比如:
function yourcontroller($scope){
var $scope.formData={};
$http({
method:'POST',
url:'insert.php',
data:$.param($scope.formData)
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
}) .then(onSuccess,onError)
function onSuccess(data){
//handle success
}
function onError(reason){
//handle error
}
}
<input ng-model="formData.yourName">
<input ng-model="formData.lstName">
<input ng-model="formData.password">
function yourcontroller($scope){
var $scope.formData={};
$http({
method:'POST',
url:'insert.php',
data:$.param($scope.formData)
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
}) .then(onSuccess,onError)
function onSuccess(data){
//handle success
}
function onError(reason){
//handle error
}
}
.then(function(data){
alert(data);// handle data
}, function(error) {
//handle error
});