我有一個奇怪的問題,讓我瘋了! 我想通過使用jquery-form版本3.46.0來提交ajax的HTML表單,然後在服務器上獲取POST數據,但我的提交按鈕的名稱不會顯示在POST數據中!也許這個lib有什麼問題?提交按鈕名稱將不會張貼在表單提交時使用jQuery的形式
這是我的代碼:
<form id="form" action="test.php" method="post">
<input name="email" type="email" placeholder="Email" required>
<!-- And yes! I didn't use an input with type submit because
I need my button to have some HTML content and applied css styles to them. -->
<button id="submit" type="submit" name="myFormName">
<span class="label">Submit</span>
</button>
</form>
<div id="formResult" style="display: block; margin: 20px 0; padding: 10px; background-color: #fbe6e6;" role="alert"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="//oss.maxcdn.com/jquery.form/3.50/jquery.form.min.js"></script>
<script>
jQuery(document).ready(function($) {
$('#submit').on('click', function(e) {
e.preventDefault();
$('#form').ajaxSubmit({
clearForm: true,
target: '#formResult',
success: function() {
// do sth
},
error: function() {
// do sth
}
});
});
});
</script>
這是test.php的文件:
<?php
var_dump($_POST);
我需要我的提交按鈕的名稱出現在服務器POST數據如預期...但它不!有人有任何想法嗎?
我沒有看到任何問題,我的身邊,按鈕有一個spining圖標test.php顯示輸入的電子郵件 –
您只需刪除您的按鈕名稱'name =「myFormName」' – Nawin
當然test.php顯示電子郵件輸入...但它不顯示包含在POST數據中的提交按鈕的名稱。你知道我的意思? – Ali