รายละเอียดของการตอบ ::
<?
$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
$objDB = mysql_select_db("uog");
$strSQL = "SELECT * FROM member WHERE 1 AND NRIC = '".$_POST["sNRIC"]."' OR Email = '".$_POST["sEMail"]."' ";
$objQuery = mysql_query($strSQL) or die (mysql_error());
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysql_close($objConnect);
echo json_encode($resultArray);
?>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#NRIC,#Email").change(function(){
$("#sNRIC").empty();
$("#sEmail").empty();
$.ajax({
url: "returnCustomer1.php" ,
type: "POST",
data: 'sNRIC=' +$("#NRIC").val()+'&sEmail='+$("#Email").val()
})
.success(function(result) {
var obj = jQuery.parseJSON(result);
if(obj != '')
{
$.each(obj, function(key, inval) {
if($("#NRIC").val() == inval["NRIC"])
{
$("#sNRIC").html(" <font color='red'>รหัสลูกค้านี้มีอยู่แล้ว</font>");
}
if($("#Email").val() == inval["Email"])
{
$("#sEmail").html(" <font color='red'>อีเมล์นี้มีอยู่แล้ว</font>");
}
});
}
});
});
});
</script>