我遇到了一个奇怪的问题,我会尽力解释。我正在使用jQuery对话框进行表单提交,除了我第一次打开表单并单击提交时,它提交表单并正确输入数据库中的所有工作。但是,如果我再打开另一个表单并提交它会创建2个相同数据的帖子。它会在每次提交时将帖子递增1。如果我刷新浏览器,它会发布1个正确的条目。为什么我必须不断刷新浏览器才能正确发布?我已经发布了我正在使用的代码,如果有人能告诉我我的错误,我将不胜感激。非常感谢
PS。假设与db的所有连接都是正确的。
jQuery dialog code
==================================================
function feedbacknew()
{
$("#form").dialog(
{
autoOpen: false,
resizable: false,
modal: true,
title: 'Submit a feedback request',
width: 460,
height: 490,
beforeclose: function(event, ui) { $("#message").html(""); }
});
$('#submit').click(function ()
{
var name = $('.uname').val();
var company = $('#company').val();
var email = $('.email').val();
var position = $('.position').val();
var feedback = $('.feedbacknew').val();
var data = 'uname=' + encodeURIComponent(name) + "&company=" + encodeURIComponent(company) + "&email=" + encodeURIComponent(email) + "&position=" + encodeURIComponent(position) + "&feedback=" + encodeURIComponent(feedback);
$.ajax(
{
type: "POST",
url: "feedback.php",
data: data,
success: function (data) {
$("#feedback").get(0).reset();
$('#message').html(data);
//$("#form").dialog('close');
$("#flex1").flexReload();
}
});
return false;
});
$("#form").dialog('open');
}
![html form code
====================================================
// Feedback form
<div id="form" style="display:none;">
<form method="post" id="feedback" class="webform" name="feedback">
<label for="company">Company</label>
<select name="company" id="company">
<option SELECTED VALUE="">Select an option</option>
<option value="Technical">Technical</option>
<option value="Database">Database</option>
<option value="Error">Error</option>
<option value="Other">Other</option>
</select>
<label for="name">Full Name:</label>
<input id="uname" name="uname" type="text" class="text ui-widget-content ui-corner-all inputbox uname" value="<?php echo $_SESSION['kt_name_usr']; ?>" />
<label for="email">Email address:</label>
<input id="email" name="email" type="text" class="text ui-widget-content ui-corner-all inputbox email" value="<?php echo $_SESSION['kt_email_usr']; ?>"/>
<label for="position">Position:</label>
<input id="position" name="position" type="text" class="text ui-widget-content ui-corner-all inputbox position" />
<label for="feedbacknew">Feedback:</label>
<textarea id="feedbacknew" name="feedbacknew" cols="25" rows="3" type="text" class="text ui-widget-content ui-corner-all inputbox feedbacknew">Please make sure that any error messages or numbers are listed here </textarea><br />
<button id="submit" class="submit">Submit</button>
<div id="message"></div>
</form>
</div>
deedback.php code
=============================================
<?php
$company = $_POST['company'];
$name = $_POST['uname'];
$email = $_POST['email'];
$position = $_POST['position'];
$feedback = $_POST['feedback'];
?>
<div style="padding:2px; color:#ff0000;font-size:12px;font-weight:normal"><?php echo "<br />" . "Thank you. You can now close this window." . "<br />"; ?></div>
<?php
mysql_query("INSERT INTO feedback (department, name, email, position, feedback, date) VALUES ('$company', '$name', '$email', '$position', '$feedback', NOW())");
?>][1]