【发布时间】:2013-12-21 12:33:18
【问题描述】:
好的,所以我知道这个 ajax 有效,但我似乎无法理解为什么它没有在这里提交。
<script type="text/javascript">
$(function(){
$('input[type=submit]').click(function(){
$.ajax({
type: "POST",
url: "postitem.php",
data: $("#myform").serialize(),
beforeSend: function(){
$('#result').html('<img src="loading.gif" />');
},
success: function(data){
$('#result').html(data);
}
});
});
});
提交表格
<form action="" method="post" onsubmit="return false;" id="myform">
提交按钮
<input type="hidden" value="Post" name="submit" />
<button type="submit" title="Done" style="height:33px; width:50px">
<img src="../../css/images/plus_25.png" />
</button>
我的按钮有点问题,但我想保持按钮的方式,因为我的许多其他表单都使用相同的按钮,谢谢你能向我解释为什么点击这个提交按钮什么都不做。
【问题讨论】:
-
您的表单中没有
input[type=submit]。你有一个button[type=submit]和一个input[type=hidden] -
所以只需将 input[type=sumbit] 更改为 button[type=submit] ?
-
<button type="submit">毫无意义。type仅存在于<input>。 -
type属性对<button>有效:developer.mozilla.org/en-US/docs/Web/HTML/Element/…
标签: javascript php jquery ajax forms