Ich arbeite an AngularJs über eine Woche und ich versuche, einen Wert in MySQL-Datenbank über eine PHP einzufügen.HTTP-Anfrage in AngularJS
meine form
aussehen wie dieses
<form ng-model="far_form" name="far_reg" ng-submit="register(far_reg.$valid)" novalidate="true"
ng-controller= "farform_contr">
<input type="text" id="First Name" placeholder="Name" ng-model="far.first_name" >
<input type="text" id="Email" placeholder="Email" ng-model="far.email">
<input type="text" id="Mobile" placeholder="Mobile" ng-model="far.mobile">
</form>
Und Controler is
.controller('farform_contr',['$scope', '$http', function($scope, $http) {
$scope.register = function(isValid) {
if (isValid) {
$http({
method : 'POST',
url : 'submit.php',
dataType: 'json',
data : $scope.far, //forms user object
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
}).
success(function(data, status) {
console.log(far);
$scope.status = status;
$scope.data = data;
})
}else{
alert('Form is not valid');
}
}
}]);
Ich habe einige andere Controller in der gleichen Datei, die fein arbeiten.
submit.php
ist
<?php
$post_date = file_get_contents("php://input");
$data = json_decode($post_date);
$name=$data['first_name'];
$email=$data['email'];
$mobile=$data['mobile'];
echo "<script>alert('$name')</script>";
echo "<script>alert('$email')</script>";
echo "<script>alert('$mobile')</script>";
?>
Alle Echos zurückkehren null ich weiß nicht, wo ich falsch gehe.
Wenn Sie den Dienst "$ http" verwenden, lautet die Methode zum Abrufen der Antwort " argument.data' in der Erfolgsfunktion. Hast du irgendeine Antwort auf Erfolg? – Harish