1

I have this notification page (page before going to register page) this page check data from database, if false / true will show message under textbox, but its only to show that message not block process input. This one my notification page (show true message if from check.php no conflic):

<head>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/settings.js" type="text/javascript"></script>
<SCRIPT type="text/javascript">
pic1 = new Image(16, 16); 
pic1.src = "img/loader.gif";
//untuk nim
$(document).ready(function(){
$("#cekintern").change(function() { 
var nomor = $("#cekintern").val();
if(nomor.length >= 8)
{
$("#status2").html('<img src="img/loader.gif" align="absmiddle">&nbsp;Checking availability...');
    $.ajax({  
    type: "POST",  
    url: "check.php",  
    data: "cekintern="+ nomor,  
    success: function(msg){  
   $("#status2").ajaxComplete(function(event, request, settings){ 
    if(msg == 'OK')
    { 
        $("#cekintern").removeClass('object_error'); // if necessary
        $("#cekintern").addClass("object_ok");
        $(this).html('&nbsp;<img src="img/accepted.png" align="absmiddle"> <font color="Green"> Available </font>  ');
    }  
    else  
    {  
        $("#cekintern").removeClass('object_ok'); // if necessary
        $("#cekintern").addClass("object_error");
        $(this).html(msg);
    }    
   });
 } 
  }); 
}
else
    {
    $("#status2").html('&nbsp;<img src="img/decline.jpg" align="absmiddle">  <font color="red">Maaf NIM anda salah.</font>');
    $("#cekintern").removeClass('object_ok'); // if necessary
    $("#cekintern").addClass("object_error");
    alert('Maaf NIM salah!!'); window.location.href='?get=2';
    }
});
});
//-->
</SCRIPT>
</head>
<body><br />
<form name="form1" method="post" action="register.php">
<center>
<em>Input <strong>NIM</strong></em><br />
    <input name="cekintern" type="text" id="cekintern" size="15" maxlength="9" placeholder="Input NIM Here"/><div id="status2"></div><br />
    <input type="submit" value="Confirm" />
    <input type="button" name="button" id="button" value="Cancel" onClick="window.location='index.php'"/></center>
</form>

and this one check.php to check from database and show message error if has conflic:

<?php if(isSet($_POST['cekintern']))
{
$nimintern = $_POST['cekintern'];
$sql_check = mysql_query("SELECT * FROM {$prefix}intern WHERE nim='$nimintern'");
if(mysql_num_rows($sql_check))
{
$nimintern = $_POST['cekintern'];
$sql_check2 = mysql_query("SELECT * FROM {$prefix}pengguna WHERE nim_pengguna='$nimintern'");
if(mysql_num_rows($sql_check2))
{
echo '&nbsp;<img src="img/decline.jpg" align="absmiddle"> <font color="red">Maaf NIM <STRONG>'.$nim.'</STRONG> nim anda sudah terdaftar.</font>';
return false;
}
else
{
echo 'OK';  
}}
else
{
echo '&nbsp;<img src="img/decline.jpg" align="absmiddle"> <font color="red">Maaf NIM <STRONG>'.$nim.'</STRONG> tidak ada dalam daftar mahasiswa.</font>';
return false;
}}
?>

all message is works, but im confuse what should i write to make notification.php (javascrit) & check.php (php) cancel input if the message is has conflic.

4

1 回答 1

0

您在成功的 ajax 回调中有此代码,如果发生冲突,您可以只添加一条指令:

$("#status2").ajaxComplete(function(event, request, settings){ 
if(msg == 'OK')
{ 
    $("#cekintern").removeClass('object_error'); // if necessary
    $("#cekintern").addClass("object_ok");
    $(this).html('&nbsp;<img src="img/accepted.png" align="absmiddle"> <font color="Green"> Available </font>  ');
}  
else  
{  
    $("#cekintern").removeClass('object_ok'); // if necessary
    $("#cekintern").addClass("object_error");
    $(this).html(msg);
    $("#cekintern").val("");/******/
}
于 2013-02-10T14:23:34.257 回答