我正在尝试提交表单数据而不使用 jQuery 刷新页面。我已经在正确的位置添加了以下所有代码,但是页面刷新并且没有发生任何事情,它既没有回显成功数据,也没有将任何数据插入 sql db。这是我想要做的;
HTML:
$profile_comments = '
<form action="#" method="post">
<table border="0" cellspacing="'.$theme['borderwidth'].'" cellpadding="'.$theme['tablespace'].'" class="sideboxes_tborder">
<tr>
<td class="sideboxes_thead">Post Comments</td>
</tr>
<tr>
<td class="sideboxes_trow">
<input type="text" class="textbox_comment" name="message" id="pc_message" tabindex="1" autocomplete="off" />
</td>
</tr>
<tr>
<td class="sideboxes_trow" align="left">
<input type="hidden" name="uid" value="'.$memprofile['uid'].'" />
<input type="hidden" name="from_uid" value="'.$mybb->user['uid'].'" />
<input type="submit" class="button" id="comment_submit" name="submit" value="Post Comment" tabindex="2">
</td>
</tr>
<tr>
<td class="sideboxes_trow"><div id="show_profile_comments" style="overflow: auto; max-height: 313px;"></div></td>
</tr>
</table>
</form>';
jQuery:
jQuery.noConflict();
jQuery(document).ready(function($)
{
$("#comment_submit").click(function()
{
var message = $( "#pc_message" ).val(),
if (message == '')
{
alert( "Message is missing!!" );
return;
}
$.ajax(
{
type : "post",
dataType: "html",
url : "pro_profile.php?action=do_comment",
data : "message=" + message,
success : function(response)
{
$('#show_profile_comments').html(response);
}
document.getElementById('pc_message').value = '';
document.getElementById('pc_message').focus();
if (response.error)
{
alert(response.error);
}
});
});
});
PHP:
if ($_POST['action'] == "do_comment")
{
$uid = intval($mybb->input['uid']);
$insert_array = array(
"uid" => $uid,
"from_uid" => intval($mybb->input['from_uid']),
"approved" => '1',
"message" => $db->escape_string($mybb->input['message']),
"dateline" => TIME_NOW
);
$db->insert_query("pp_comments", $insert_array);
$query = $db->simple_select("pp_comments", "*", "uid='{$uid}'");
$c = $db->fetch_array($query);
echo $c['message'];
}
请帮忙!