リンク、ボタン、フォーム送信など、div 内のすべてのクリック イベントを処理する jquery 関数を作成しました。フォームの送信以外はすべて正常に機能します。たとえば、ページの1つに次のフォームがあります。
<form name="form" method="post" action="">
<p>Enter a Start date for review <font color="red"><b>(mm/dd/yyyy)</b></font>
:
<input type="text" name="StartDate" id="startDate" maxlength="10" size="15">
<br /> <label id="label1" style="color: red"></label>
<p>Enter a deadline for review <font color="red"><b>(mm/dd/yyyy)</b></font>
:
<input type="text" name="txtDate" id="txtDate" maxlength="10" size="15">
<br /> <label id="label2" style="color: red"></label>
</p>
</br>
</br>
</br>
<input type ="submit" name="submitCrit" value="submit"></input></br>
</form>
<?php
if (isset($_POST['txtDate']) && isset($_POST['StartDate'])) { // checking if values passed
$todays_date = date("m/d/Y"); // getting today's date to check with it
$today = strtotime($todays_date); // parsing it to timestamp
$to = date('Y-m-d', str_replace('-', '/', $today)); // replacing / with -
$date = strtotime($_POST['txtDate']); // parsing enddate to timestamp
$newdate = date('Y-m-d', str_replace('-', '/', $date)); // replacing / with -
$startdate = strtotime($_POST['StartDate']); // parsing startdate to timestamp
$startnewdate = date('Y-m-d', str_replace('-', '/', $startdate)); // replacing / with -
if ($newdate != null && $newdate > $to
&& $startnewdate != null && $startnewdate < $newdate
&& $startnewdate > $to) {
$con = mysql_connect('localhost', 'root', ""); //db connection
if (!$con) {
die('connection error');
} else {
mysql_select_db("mydb", $con);
$query = "
UPDATE conference
SET rev_startDate = '{$startnewdate}', rev_endDate = '{$newdate}'
WHERE conference_id = {$confID}
";
echo '<script type="text/javascript">'
, 'ChangeText("deadline set successfuly");'
, '</script>';
if (!mysql_query($query, $con)) {
echo "query not run";
}
mysql_close($con);
}
} else {
echo '<script type="text/javascript">'
, 'ChangeText("invalid deadline");'
, '</script>';
}
}
?>
そして、クリックイベントを処理するこのthw関数:
$(document).ready(function() {
$('#mydiv').delegate('form', 'submit', function() {
var page = $(this).attr('action');
if (page == "") {
return true;
}
else {
$('#mydiv').fadeOut('slow',function() {
$('#mydiv').load(page, function () {
$(this).fadeIn('slow');
});
});
return false;
}
});
return false;
});
ただし、送信をクリックすると、空白のページのみが div 内に読み込まれ、php スクリプトが機能せず、ウェブサイトの他のすべてのフォームでも同じ問題が発生します。誰が問題がどこにあるか知っていますか?