$ . post()应用

index . html内容如下:

& lt; !DOCTYPE html>

& lt; html>

& lt; head>

& lt;元charset=皍tf-8"在

& lt;元http-equiv=癤-UA-Compatible"内容=癐E=edge"在

& lt; title> & lt;/title>

& lt;链接rel=皊tylesheet"https://www.yisu.com/zixun/href=" ">

& lt;风格类型=拔谋?css"媒体=皊creen"祝辞

ul {

list-style:没有。

}

& lt;/style>

& lt;/head>

& lt; body>

& lt; h2>用户Login

& lt; ul>

& lt; li> Username

& lt; li> & lt;输入类型=皌ext"name=皍sername"id=皍sername"占位符=扒胧淙雞sername"类=癷pt-style"/祝辞;& lt;/li>

& lt; li> Password

& lt; li> & lt;输入类型=皃assword"name=皃assword"id=皃assword"占位符=皃laease password"进来的;类=癷pt-style"/祝辞;& lt;/li>

& lt; li> & lt;输入类型=癰utton"name=癮jaxBtn"id=癮jaxBtn"价值=https://www.yisu.com/zixun/" ajaxLogin "/>

& lt;/ul>

& lt;脚本https://www.yisu.com/zixun/src=" http://code.jquery.com/jquery-1.7.2.min.js " type=" text/javascript ">

& lt;脚本类型=拔谋?javascript"在

$(文档)时(函数(){

$ (“# ajaxBtn") .click(函数(){

,,,,$ . post (“index.php", $ (“.ipt-style") .serialize()函数(res) {

,,,,,,console.log (res);

,,,,});

,,});

});

& lt;/script>

& lt;/body>

& lt;/html>


index . php内容如下:

& lt; ? php

头(“内容类型:text/html; charset=utf-8");

$ username=$ _POST[& # 39;用户名# 39;];

$密码=$ _POST[& # 39;密码# 39;];


$ res=数组(& # 39;代码# 39;=祝辞1 & # 39;味精# 39;=祝辞& # 39;& # 39;,& # 39;数据# 39;=祝辞[]);

if ($ username==& # 39;前# 39;,,密码==& # 39;美元123456 & # 39;){

,,$ res[& # 39;味精# 39;]=皊uccess";其他

} {

res美元[& # 39;代码# 39;]=0;

res美元[& # 39;味精# 39;]=& # 39;失败# 39;;

}

回声json_encode (res);

 $ . post()应用“> </p><h2 class=$ . post()应用