我读到了类似的问题,但我无法找到它为什么在这里执行它。 基本上jquery ajax调用发送一些信息提交。问题在于表单首次提交一次,然后第二次提交两次,第三次提交4次。我不明白问题在哪里。能否请你帮忙?JQuery Ajax调用根据时间提交更多次
$('#form10').submit(function() {
//Get the data from all the fields
var UserID = $('input[name=UserID]');
var problemID = $('input[name=problemID]');
var solution_text = $('textarea[name=solution_text]');
var MM_insert = $('input[name=MM_insert]');
//organize the data properly
var data = 'UserID=' + UserID.val() + '&problemID=' + problemID.val() + '&solution_text=' + solution_text.val() + '&MM_insert=' + MM_insert.val();
//show the loading sign
$('.loading').show().delay(1200).fadeOut();
//start the ajax
$.ajax({
//this is the php file that processes the data
url: "/js/ajax/add-comment.php",
//POST method is used
type: "POST",
//pass the data
data: data,
//Do not cache the page
cache: false,
//success
success: function (html) {
//if process.php returned 1/true (success)
if (html == 1) {
//hide the gif
$('.loading').fadeOut('slow');
//show the success message
$('#comment-success').delay(1000).slideDown('slow').delay(2000).slideUp('slow');
$('#comments').load('/js/ajax/comments2.php?problemID=' + problemID.val());
//if process.php returned 0/false (failed)
} else {
$('#error-msg2').show('slow');
}
}
});
//cancel the submit button default behaviours
return false;
});
PHP回代码
.............
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "comments")) {
$insertSQL = sprintf("INSERT INTO solution (UserID, solution_date, problemID, solution_text) VALUES (%s, %s, %s, %s)",
GetSQLValueString($UserID, "int"),
GetSQLValueString(date('Y-m-d H:i:s', mktime()), "text"),
GetSQLValueString($problemID, "int"),
GetSQLValueString($solution_text, "text"));
mysql_select_db($database_tccconn, $tccconn);
$Result1 = mysql_query($insertSQL, $tccconn) or die(mysql_error());
if($Result1) { echo '1';}
else
{ echo '0';}
}
形式
form method="post" action="" name="form10" id="form10">
代码FRM comments2
mysql_select_db($database_tccconn, $tccconn);
$query_rstcomments = sprintf("SELECT solution.solutionID, solution.UserID, solution.solution_date, solution.solution_text, solution.problemID, user.org_name FROM solution NATURAL JOIN user WHERE solution.problemID = %s ORDER BY solution.solutionID ASC", $colname_rstcomments);
$rstcomments = mysql_query($query_rstcomments, $tccconn) or die(mysql_error());
$row_rstcomments = mysql_fetch_assoc($rstcomments);
$totalRows_rstcomments = mysql_num_rows($rstcomments);
if($rstcomments) {
do { ?>
} ?>
Posted by<?php echo ucwords(stripslashes($row_rstcomments['org_name'])); ?>
On <?php echo date("j F Y",strtotime($row_rstcomments['solution_date'])); ?>
at <?php echo date("H:i",strtotime($row_rstcomments['solution_date'])); ?>