我有一个文本框,一旦用户从该文本框中聚焦,我想使用 jquery-ajax 对其进行验证。
验证包括:
服务器端,值转到 php 页面,我必须验证它
如果验证成功,则显示警报(“成功”);否则如果错误警报(“失败”);
我怀疑 jquery ajax 将如何显示 alert("failure"); 到现在为止,我所做的只是为了成功。
我只知道下面提到的代码,我应该怎么做才能解决我的问题?请帮忙
<script type="text/javascript">
$(function()
{
$('input[id^="datepicker"]').on('focusout',function()
{
$.ajax({
url: "ajax_frmdate_validation.php?txtval="+$(this).val(),
success: function(data){
alert('Successfully ...');
}
});
});
});
</script>
--------------
--------------
<input class="plain" name="frmdate" value="" size="25" id="datepicker" />
我的服务器端php代码是:
$txtval =$_REQUEST['txtval'];
$fromTimestamp = strtotime( $txtval);
//---------My Logic Code Goes Here -----------------------------
$sid=$_SESSION['id'];
$result12=mysql_query("SELECT * FROM budget where creater_id = '$sid'");
$num_rows = mysql_num_rows($result12);
if($num_rows>0)//check if empty or not
{
while($test12 = mysql_fetch_array($result12)) {
$from_date = strtotime($test12['from_date']);//getting all the FROM-Dates_column
$to_date = strtotime($test12['to_date']);//getting all the TO-Dates_column
if(isset($to_date) && isset($from_date)) {
if((($fromTimestamp >= $from_date) && ($fromTimestamp <= $to_date)) || (($toTimestamp >= $from_date) && ($toTimestamp <= $to_date))) {
$val = 'Y'; //return Y in meet this condition
}
else {
$val = 'N'; // return N if meet this condition
}
}
//---------------------Result of my logic code---------------------------------
if($val == 'Y') //Returns TRUE
{
//VALIDATION FAILS - Returns Validation Error
break;
}
else if($val == 'N') {
//VALIDATION TRUE - Returns Validation Error
}
}
}