第44行中的if ... else不起作用。我检查了jQuery post返回的值,它返回'Y'或'N'。我正在测试这个条件并根据返回的值执行一些任务。但是那部分不起作用,内部的警报既不工作也没有其他的show事件正在工作。无法找到错误。
<?php
require_once('Connections/met.php');
session_start();
include('include/wbc_menu_select.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- DW6 --><head>
<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Environmental Survey Laboratory: : Home</title>
<link rel="stylesheet" href="css/home_style.css" type="text/css" />
<link rel="stylesheet" href="css/wbc.css" type="text/css" />
<script type="text/javascript" src="js/jquery-1.5.1.js"></script>
<script type="text/javascript" src="js/jquery-ui/js/jquery-ui-1.10.1.custom.js"></script>
<script type="text/javascript" src="js/jquery-ui/js/jquery-ui-1.10.1.custom.min.js"></script>
<link rel="stylesheet" href="jquery-ui/css/smoothness/jquery-ui-1.10.2.custom.min.css" type="text/css" media="screen" />
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('#tldno').focus();
jQuery( "#datepicker" ).datepicker({ yearRange: "-60:-18", changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy", altFormat:"yy-mm-dd",altField:"#stddate" });
jQuery('#submit').hide();
});
jQuery("#tldno").change(function(){
var rep_sel=jQuery("[name='unit']:checked").val();
var name = rep_sel.concat(jQuery("#tldno").val());
jQuery.post("tld_search_hpu.php", {"name":name}, function(data) {
if(data=='Y'){alert("Data Exists"); }
else{ jQuery('#submit').show(); }
});
});
</script>
<style type="text/css">
.wbcmenu{
vertical-align:middle;
padding-top:100px;
height:200px;
}
.opt_tbl{
border-collapse: collapse;
width:auto;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color:#000066;
margin-top:-75px;
}
#countdata{
width:500px;
float:left;
border:solid;
}
#personaldata{
background-color:#FFFF99;
color:#FF0000;
font-size:12px;
}
.new{
border-collapse: collapse;
width:auto;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color:#000066;
}
.new td {
padding:5px;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
text-align:left;
}
.titl{
color:#CC0033;
}
.na{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
color:#FF0066;
font-weight:bold;
}
fieldset{
width:500px;
border:1px solid green
}
label {
float:left;
width:50%;
margin-right:0.5em;
padding-top:0.2em;
text-align:right;
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
font-size:12px;
height:20px;
}
input {
font-family: 'Lucida Grande', Tahoma, Verdana, sans-serif;
font-size: 14px;
}
div.ui-datepicker{
font-size:12px;
}
</style>
</head>
<body>
<!-- DO NOT MOVE! The following AllWebMenus linking code section must always be placed right AFTER the BODY tag-->
<!-- ******** BEGIN ALLWEBMENUS CODE FOR wbcmenu ******** -->
<script type="text/javascript">var MenuLinkedBy="AllWebMenus [4]",awmMenuName="wbcmenu",awmBN="766";awmAltUrl="";</script><script charset="UTF-8" src=<?php echo '"'.$menu_script.'"';?> type="text/javascript"></script><script type="text/javascript">awmBuildMenu();</script>
<!-- ******** END ALLWEBMENUS CODE FOR wbcmenu ******** -->
<div id="main">
<div id="masthead"></div>
<!-- end masthead -->
<div id="content">
<div id="menu"></div>
<br/>
<br/>
<?php
if (isset($_SESSION['EMPNO'])){
$user_type=$_SESSION['wbc_user_type'];
$user_section=$_SESSION['wbc_user_section'];
$user_unit=$_SESSION['wbc_user_unit'];
$user_admin=$_SESSION['wbc_admin'];
}
else
{
header('Location:wbc_login.php');
exit();
}
?>
<div id="pers_form">
<br/>
<br/>
<form id="personnel_data">
<fieldset >
<legend> Personnel Data</legend>
<label for "kgsunit">Select KGS Unit </label><input name="unit" type="radio" value="1" <?php if($user_unit=='1'){echo 'checked="checked" ';}?>/> 1&2<input name="unit" type="radio" value="3" <?php if($user_unit=='3'){echo 'checked="checked" ';}?> /> 3&4<input name="unit" type="radio" value="6" <?php if($user_unit=='6'){echo 'checked="checked" ';}?> /> 5&6<br/>
<label for "tld">TLD No. </label>
<input type="text" id="tldno" name="tldno" size="25" maxlength="25" onkeydown="if(event.keyCode==13) event.keyCode=9;"/><br/>
<label for "fname">Full Name</label><input type="text" id="fname" name="fname" size=30 maxlength=30onKeyDown="if(event.keyCode==13) event.keycode=9;"/><br/>
<label for "dob">Date of Birth</label><input type="text" id="datepicker" name="datepicker" /><input type="hidden" id="stddate" name="stddate" value="<?php echo $dateus; //echo date('d-m-Y'); ?>"/><br/>
<label for "cat"> Category</label><input name="cat" type="radio" value="R" checked="checked" />
Regular
<input type="radio" name="cat" value="C" />Casual<br/>
<div id="emp"><br/><label for "ccno">CC No.</label><input type="text" name="ccno" value="0" size=25 maxlength=25 onkeydown="if(event.keyCode==13) event.keyCode=9;"/><br/>
<label for "empno">Employee No.</label><input type="text" name="empno" value="0" size=25 maxlength=25 onkeydown="if(event.keyCode==13) event.keyCode=9;"/></div><br/>
<label for "section">Section</label><select name="section">
<?php
$db=mysql_select_db($database_met,$met) or die("could not connect");
$secsql= "SELECT *
FROM sections
ORDER BY secname;
";
$result_sec=@mysql_query($secsql) or die(mysql_error());
echo'<option value="" selected="selected">Select Section</option>';
while($row2=mysql_fetch_array($result_sec))
{ echo($row2['secname']);
echo"<option>".$row2['secname']."</option>";}
?>
</select>
<label for "height"> Height in cm</label><input type="text" name="height" value="0" size=25 maxlength=25 onkeydown="if(event.keyCode==13) event.keyCode=9;"/></td>
<input id="submit" type="submit" name="submit" value="Add record" /></td>
</form>
</div>
<br />
</div>
<p>
<!--end content -->
</p>
<p>
<div id="navBar"></p><?php include('cssmenu.php');?> </div>
<!--end navbar -->
<div id="siteInfo"><?php include('footer.php');?> </div>
<br />
</div>
</body>
</html>
答案 0 :(得分:1)
为每个人的理智添加一些格式。另外,看看我放置console.log的位置,它应该可以帮助你弄清楚if语句中的确切内容。
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('#tldno').focus();
jQuery( "#datepicker" ).datepicker({
yearRange: '-60:-18',
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
altFormat:"yy-mm-dd",
altField:"#stddate"
});
jQuery('#submit').hide();
});
jQuery("#tldno").change(function(){
var rep_sel=jQuery("[name='unit']:checked").val();
var name = rep_sel.concat(jQuery("#tldno").val());
jQuery.post('tld_search_hpu.php', {name: name}, function(data) {
console.log(data);
if (data === 'Y') {
alert("Data Exists");
} else {
jQuery('#submit').show();
}
});
});