如何在登录成功时显示警报 [英] How to display alert when login is successful

查看:89
本文介绍了如何在登录成功时显示警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

index.php



index.php

<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





script.js

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');})
		 	};
 	}







authenticate.php





And
authenticate.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;  */
	
	 
?>

推荐答案

范围,


http){

http) {  


scope.submitForm = function ()
{
console.log( 发布数据....);
scope.submitForm = function ()  {  console.log("posting data....");  


这篇关于如何在登录成功时显示警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆