Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
index.php

HTML
<html>

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.9.0/ui-bootstrap-tpls.min.js"></script>
<script src="js/script.js"></script>

<div id="container" ng-app="myApp">
 <section>
 <form class="form-inline" ng-controller="FormController" ng-submit="submitForm()" role="form" method="post">
 <div class="form-group">
 <label class="sr-only" for="Source Station">Insert Your Name</label>
 <input type="text" ng-model="username" placeholder="John" class="form-control" >
 </div>
 <div class="form-group">
 <label class="sr-only" for="Source Station">Insert Your City</label>
 <input type="text" ng-model="password" placeholder="Perth" class="form-control" >
 </div>
 <button type="submit" class="btn btn-primary">Submit Record</button>

</form>
</section>
</div>


</html>


script.js

JavaScript
var App = angular.module('myApp', ['ui.bootstrap']);
 function FormController($scope, $http) {

 $scope.submitForm = function ()
 {
 console.log("posting data....");
 $http({
             method: 'POST',
			 url: 'authenticate.php',
			headers: {'Content-Type': 'application/json'},
			/*headers : {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'},*/
			data: JSON.stringify({username: $scope.username,password:$scope.password})
			 }).success(function (data){
				  alert(data);
				  console.log(data);
		 		 $scope.message = data.status;
				alert(data);
				alert($scope.message);
				alert(data.status);
				alert(data.result);
		 	}).error(function(err){alert('aaaaa');})
		 	};
 	}


And
authenticate.php

PHP
function ob_file_callback($buffer)
{
  global $ob_file;
  fwrite($ob_file,$buffer);
}

$ob_file = fopen('test.txt','w');

ob_start('ob_file_callback');

	$postd = file_get_contents('php://input');
	$request = json_decode($postd);
	//print_r($request);
	$username = $request->username;
	$password = $request->password;
	  
   //echo($username);
	
	//echo($password);
	
	if( $username=="service" && $password == "service@123" )
	{
		//echo $result = "{'status':'1'}";
		echo $result=1;
	}
	else
	{
		//echo $result = '{"status":"2"}';
		echo $result=2;
	}
	echo json_encode($result);
	//$name= $request->name;
	//$city= $request->city;
	//echo json_encode($name);
	//print_r ($name);
	//print_r ($city);
	/*//$postdata = file_get_contents('php://input');
   //  $request = json_decode($postdata);
    //  $name = $postdata->name;
     // $city = $postdata->city;
	//Parse error:   in C:\xampp\htdocs\newaj\login.php on line 17<br />
	//echo $name;  */
	
	 
?>
Posted
Updated 28-Sep-15 20:43pm
v2
Comments
John C Rayan 29-Sep-15 6:40am    
What error are you getting?

1 solution

You have to use

$window.alert() method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900