作者:木棉 | 来源:互联网 | 2023-05-19 16:03
Iamtryingtoinsertdatafromfrontendtomysqldbusingangularjs.Butitisnotgetinginserted
I am trying to insert data from front end to mysql db using angularjs. But it is not geting inserted to the db even though there are no error messages. Following is the code that I use.
我正在尝试使用angularjs从前端插入数据到mysql db。但是即使没有错误消息,它也不会插入到db中。下面是我使用的代码。
index.html
index . html
script.js
script.js
demoApp.config( function ($routeProvider,$locationProvider) {
$routeProvider
.when('/',
{
controller: 'SimpleController',
templateUrl: 'Partials/view1.html'
})
.when('/view2',
{
controller: 'SimpleController',
templateUrl: 'Partials/view2.html'
})
.otherwise({redirectTo: '/'});
});
demoApp.controller('SimpleController',function ($scope,$http){
$http.post('server/view.php').success(function(data){
$scope.friends = data;
});;
$scope.addNewFriend = function(add){
var data = {
fname:$scope.newFriend.fname,
lname:$scope.newFriend.lname
}
$http.post("server/insert.php",data).success(function(data, status, headers, config){
console.log("inserted Successfully");
});
$scope.friends.push(data);
$scope.newFriend = {
fname:"",
lname:""
};
};
});
View1.html
View1.html
and following is my php file
下面是我的php文件
insert.php
insert.php
I know I am doing something stupid here. I have just started to learn angularjs today. when i try the php code with plain html to insert into db it works perfectly.I am not getting what I am doing wrong here. Hope someone will help me out here
我知道我在做傻事。我今天刚开始学英语。当我尝试使用纯html的php代码插入到db中时,它会非常有效。我在这里做错了。希望有人能帮我。
1 个解决方案