【发布时间】:2014-10-31 22:06:25
【问题描述】:
我正在寻找一些简洁的解决方案,我可以在其中发送表单名称并使用表单输入字段提交按钮名称。我尝试了 form.serializeArray() 方法,但我只在帖子中获取输入字段名称。那么如何发送完整的表单数据和表单名称并在一行代码中提交按钮名称
<form id="formid" name="formName" class="formClass" action="service.php" method="POST" >
<input type="text" id="fname" name="fname"/>
<input type="text" id="lname" name="lname" />
<input type="Submit" id="SUBMIT" value="SUBMIT" name="submit"/>
</form>
$( "#formid" ).submit(function( event ) {
//var array = $(this).serializeArray() ; // Didn't send Form name and submit button
// var data2 = new FormData($( "#formid" )[0]); // I have also tried this
$.ajax({
type: $(this).attr('method'),
url : $(this).attr('action') ,
cache: false,
contentType: false,
processData: false,
data: formData,
complete:function(httpResponse, status) {
var response = httpResponse.responseText;
alert(response);
}
});
event.preventDefault();
});
我想在 ajax 中发送表单名称和提交按钮名称,就像提交表单后重新加载页面时一样。
更多我已经尝试MALSUP,我可以在 POST 数据中发送表单名称和提交按钮名称。那么在 Jquery AJAX 中执行此操作的替代方法是什么
【问题讨论】:
-
能否请您提供相关代码的示例,以便我们更好地理解问题?有关询问的信息,请参阅posting guidelines。