//?抽??锛??瑰?荤?诲???????锛?Ajax?规??ゆ??锛?涓???负login.php??????login.js浠g??
function chklg() {
if ($('lgname').value == '') {
alert('杈??ュ???');
$('lgname').focus();
return false;
}
if ($('lgchk').value != $('chknm').value) {
alert("楠?璇?????璇?");
$('lgchk').focus();
return false;
}
//?抽??锛?Ajax?峰??user_login_chk.php?版??
url = 'user_login_chk.php?act=' + (Math.random()) + '&name=' + $('lgname').value + '&pwd=' + $('lgpwd').value;
xmlhttp.open('get', url, true);
xmlhttp.send();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
msg = xmlhttp.responseText;
//?抽??锛???val灏?杩?????json瀛?绗?覆msg杞?涓?son锛?骞舵?璇?json,jsonobj.name
var jsonobj=eval('('+msg+')');
//????涓???袱?ュ???锋????
var jsonobj='';
eval('jsonobj='+msg+';');
alert(jsonobj.name);
$('name').innerHTML = jsonobj;
if (msg == '1') {
alert("?诲?????");
location = "test.php"
}
else {
alert("?诲?澶辫触");
}
}
}
}
涓???负user_login_chk.php浠g??
<?php
//????娴?璇???session_start();
header('Content-Type:text/html;charset=gb2312');
include_once 'conn/conn.php';
$name = $_GET['name'];
$pwd = $_GET['pwd'];
if(!empty($name) && !empty($pwd)){
$sql = "select name from tb_member where name = '".$name."'";
$num = $conne->getRowsNum($sql);
//$student涓烘?璇??ㄧ??php?扮?锛?
$student = array("name"=>"lisheng","age"=>"35");
$studentJson = json_encode($student);
if($num == 0 || $num == '' ){
$reback = $studentJson;
}else{
$reback = $studentJson;
}
}
echo $reback;
?>