使用angularjs和php在数据库中插入数据后的响应
我正在尝试使用带有angularjs的$http.post将数据保存到数据库中。 数据保存在db中,但我无法跟踪其成功响应 下面是我的HTML代码使用angularjs和php在数据库中插入数据后的响应,php,angularjs,Php,Angularjs,我正在尝试使用带有angularjs的$http.post将数据保存到数据库中。 数据保存在db中,但我无法跟踪其成功响应 下面是我的HTML代码 <form ng-controller="studentCntrl" name="add_user"> <div class="modal-header"> <h3 class="modal-title">Add a user by sending an invite via
<form ng-controller="studentCntrl" name="add_user">
<div class="modal-header">
<h3 class="modal-title">Add a user by sending an invite via e-mail</h3>
</div>
<div class="modal-body">
<input type="text" class="form-control" name="user_email" ng-model="user_name" placeholder="Enter a name">
<br />
<input type="text" class="form-control" name="user_name" ng-model="user_email" placeholder="Enter an e-mail adress">
</div>
<div class="modal-footer">
<!-- <button type="" class="btn btn-success" ng-click="add_user()">Invite</button> -->
<input type="button" class="btn btn-success" name="add_user" value="Invite" ng-click="save_user()">
<button class="btn btn-warning">Cancel</button>
</div>
</form>
insert.php
<?php
include('db.php');
switch($_GET['action']) {
case 'add_user' :
add_user();
break;
}
function add_user() {
$data = json_decode(file_get_contents("php://input"));
$user_name = $data->user_name;
$user_email = $data->user_email;
$qry = mysql_query('INSERT INTO register(name, user_email) VALUES ("' . $user_name . '","' . $user_email . '")');}?>
在insert.php文件中,将数据插入数据库后添加以下行
if($qry){
echo "success";
}else{
echo "Something went wrong";
}
在insert.php文件中,将数据插入数据库后添加以下行
if($qry){
echo "success";
}else{
echo "Something went wrong";
}
要读取响应,您必须在服务器端打印一些消息。我使用的是console.log(data)$http.post(“insert.php”{'user_name':$scope.user_name,'user_email':$scope.user_email})。success(函数(data,status){console.log(data);但它不是控制台任何东西。我的意思是,如果($qry){echo,在add_user()函数中执行类似的操作“success”}否则{echo“fail”}我也这样做了,它会回显响应,但不在.success(函数(数据,状态){console.log(数据)”要读取响应,你必须在服务器端打印一些消息。我使用的是console.log(数据)$http.post(“insert.php”,{'user_name':$scope.user_name,'user_email':$scope.user_email})。success(函数(数据,状态){console.log(data);但它不是console任何东西。我的意思是,如果($qry){echo“success”;}否则{echo“fail”;}我做了同样的事情,它回显响应但不在“.success”(函数(数据,状态){console.log(数据)”我做了同样的事情,它回显响应但不在“.success”(函数(数据,状态){console.log(data)“我做了同样的操作,它回显响应,但不在“.success(函数(数据,状态){console.log(数据)”