My index.html:
<form name="myForm" ng-controller="Ctrl" ng-submit="save(user)">
<label>Name:</label>
<input type="text" ng-model="user.name"/><br /><br />
<label>Email:</label>
<input type="text" ng-model="user.email"/><br /><br />
<input type="submit" value="Submit"/>
</form>
script.js
function Ctrl($scope,$http)
{
$scope.save = function(user)
{
var data={
name: user.name,
email:user.email
}
console.log(data);
$http.post("insert.php",data).success(function(data){
console.log(data);
});
}
}
insert.php
<? php
$data = json_decode(file_get_contents('php://input'), true);
if (json_last_error() === JSON_ERROR_NONE) {
// use $data instead of $_POST
print_r($data);
?>
This is my code to store form data in database.. but its not working...i am complete new to angularjs...i donno where i went wrong... pls help me..
insert.php
- is this a valid url? Haven't used php in ages but I can't remember putting .php on the end of everything! Depends on your server config of course... You might put a .error() callback and see if that returns anything. – Ian Haggerty Aug 13 '13 at 11:48