zoukankan      html  css  js  c++  java
  • Angularjs使用 ajax实例

    HTML文件:

    <!DOCTYPE html>
    <html ng-app='a72'>
    	<head>
    		<meta charset="UTF-8">
    		<title>使用$http快捷方式与服务端交互</title>
    		<script src="../angular.min146.js" type="text/javascript" charset="utf-8"></script>
    	</head>
    	<body>
    		<div class="frame" ng-controller='c72'>
    			<div class="show">
    				<div class="tip">POST返回的结果是:{{result}}</div>
    				<button ng-click="onclick()">发送</button>
    			</div>
    		</div>
    		<script>
    			angular.module('a72',[]).config(function($httpProvider){
    				$httpProvider.defaults.transformRequest=function(obj){
    					var arrstr=[];
    					for(var p in obj){
    						arrstr.push(encodeURIComponent(p)+"="+encodeURIComponent(obj[p]))
    					}
    					return arrstr.join("&");
    				}
    				$httpProvider.defaults.headers.post={
    					'Content-Type':'application/x-www-form-urlencoded'
    				}
    			})
    			.controller('c72',function($scope,$http){
    				var postdata={name:"陶国荣"}
    				$scope.onclick=function(){
    					$http.post('post.php',postdata).success(function(data,status,headers,config){
    						$scope.result=data;
    					})
    				}
    			})
    		</script>
    	</body>
    </html>
    

      PHP文件:

    <?php	
    	$str=$_POST['name'];
    	if($str=='陶国荣'){
    		echo "验证正确!";
    	}else{
    		echo "验证失败!";
    	}
    ?>
    

      

  • 相关阅读:
    I
    D
    K
    G
    J
    Doom HDU
    Mountaineers Gym
    华南理工大学“三七互娱杯”程序设计竞赛(重现赛)( HRY and array 高精度除法模板)
    Corn Fields POJ
    linux如何安装缺失依赖
  • 原文地址:https://www.cnblogs.com/chunshu/p/5649934.html
Copyright © 2011-2022 走看看