我看到 jQuery 没有收到表单的值有问题。
我在隐藏的 div 中有表单,用户单击“发送 pm”,表单出现。
<div class="interactContainers" id="private_message1">
<form action="javascript:sendPM();" name="pmForm" id="pmForm" method="post">
<font size="+1">Sending Private Message to <strong><em><?php echo "$username"; ?></em></strong></font><br /><br />
Subject:
<input name="pmSubject" id="pmSubject" type="text" maxlength="64" style="width:90%;" />
Message:
<textarea name="pmTextArea" id="pmTextArea" rows="8" style="width:90%;"></textarea>
<input name="pm_sender_id" id="pm_sender_id" type="hidden" value="<?php echo $sessionid ?>" />
<input name="pm_sender_name" id="pm_sender_name" type="hidden" value="<?php echo $user ?>" />
<input name="pm_rec_id" id="pm_rec_id" type="hidden" value="<?php echo $profileid ?>" />
<input name="pm_rec_name" id="pm_rec_name" type="hidden" value="<?php echo $username ?>" />
<input name="pmWipit" id="pmWipit" type="hidden" value="<?php echo $thisRandNum ?>" />
<span id="PMStatus" style="color:#F00;"></span>
<br /><input name="pmSubmit" type="submit" value="Submit" />
<span id="pmFormProcessGif" style="display:none;"><img src="../_Images/loading.gif" width="28" height="10" alt="Loading" /></span></form>
</div>
我有一个 JQuery 脚本来检查信息是否已输入,但它一直告诉我没有收到数据。
我不断收到“请输入主题”或“请输入消息”输出
jQuery
$('#pmForm').submit(function(){$('input[type=submit]', this).attr('disabled', 'disabled');});
function sendPM ( ) {
var pmSubject = $("#pmSubject");
var pmTextArea = $("#pmTextArea");
var sendername = $("#pm_sender_name");
var senderid = $("#pm_sender_id");
var recName = $("#pm_rec_name");
var recID = $("#pm_rec_id");
var pm_wipit = $("#pmWipit");
var url = "../_Scripts/private_msg_parse.php";
if (pmSubject.val() == "") {
$("#jqueryReply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> Please type a subject.').show().fadeOut(6000);
} else if (pmTextArea.val() == "") {
$("#jqueryReply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> Please type in your message.').show().fadeOut(6000);
} else {
$("#pmFormProcessGif").show();
$.post(url,{ subject: pmSubject.val(), message: pmTextArea.val(), senderName: sendername.val(), senderID: senderid.val(), rcpntName: recName.val(), rcpntID: recID.val(), thisWipit: pm_wipit.val() } , function(data) {
$("#jqueryReply").html(data).show().fadeOut(10000);
document.pmForm.pmTextArea.value='';
document.pmForm.pmSubject.value='';
$("#pmFormProcessGif").hide();
});
}
}
这是一个小提琴,看看发生了什么。http://jsfiddle.net/RKN39/