我想通過一個HTML Div值(Div內的整個HTML代碼)作爲通過Ajax的表單中的輸入值。 這是我的表單代碼: Div「Fetch_Applicant」動態獲取我想通過ajax傳遞的表。我用桌子更新了DIV。如何在表單中傳遞Div值作爲輸入?
//Form Starts
<form name="mail_applicant" novalidate id="mail_applicant" action="" method="post" >
<div id="fetch_applicant">
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
</div>
<input name="mail_id" id="mail_id" value="" type="email" required />
<button type="submit" id="mail_applicant" name="mail_applicant" >Send Mail</button>
</form> //Form Ends
<div id="fetch_applicant_mail"></div> //This Is Where I Am Printing The Status Of The Post.
這是我的AJAX代碼:
<script type="text/javascript">
$(document).ready(function (e) {
$("#mail_applicant").on('submit',(function(e) { /*On Submit Of Form Named Mail Applicant */
e.preventDefault();
$.ajax({
url: "send_mail_applicant.php", /*Posting The Data*/
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData:false,
success: function(data)
{
$("#fetch_applicant_mail").html(data); /*Fetching POST Status*/
},
error: function()
{
}
});
}));
});
</script> /*Script Ends*/
這是我的PHP代碼:
<?php
echo "Content".$_POST['fetch_applicant'];
echo "Mail-id:".$_POST['mail_id'];
$to = $_POST['mail_id'];
$subject = "Mail Data";
$message = $_POST['fetch_applicant'];
$headers = "From: The Server <[email protected]>" . "\r\n" .
"Content-type: text/html" . "\r\n";
mail($to, $subject, $message, $headers);
?>
當我提交表單,郵件ID是越來越貼,但股利內容沒有發佈。它仍然是空的。 $_POST['fetch_applicant']
的值始終爲NULL。
請注意,此鏈接:how to submit a div value in a form沒有幫助。
因爲他們是表的一部分,你不能發送DIV值。要麼在表單提交之前將該div值克隆到某個隱藏字段,要麼選擇每個表單元素併發布這些值。 –
@Arijit,'$ _POST ['fetch_applicant']'應該是什麼值?你想傳遞什麼,因爲它的價值? –
如果你能幫我解決代碼問題,那將會很棒。 –