jQuery 表单提交
当我提交下面的表单时,当前页面将被刷新,并且表单参数将附加到页面 URL 的末尾。为什么会出现这种情况?我需要提交表单,但隐藏表单参数。
谢谢
<div class="ui-block-b"><button id="submit" type="submit">Submit</button></div>
$("#submit").click(function(){
var formData = $("#newPostForm").serialize();
$.ajax({
type: "POST",
url: "/mobile/newpost.php",
cache: false,
data: formData,
success: onSuccess
});
return false;
});
When I submit below form the current page is refreshed and form parameters are appended to the end of the page URL. Why is this occuring ? I need to submit the form but the keep the form parameters hidden.
Thanks
<div class="ui-block-b"><button id="submit" type="submit">Submit</button></div>
$("#submit").click(function(){
var formData = $("#newPostForm").serialize();
$.ajax({
type: "POST",
url: "/mobile/newpost.php",
cache: false,
data: formData,
success: onSuccess
});
return false;
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
摆脱
type="submit"
(实际上应该是),并使其成为标准按钮,如果您不打算实际提交表单:
另一种方法是在表单上设置
onsubmit
处理程序:Get rid of the
type="submit"
(which by the why should actually be<input type="submit">
) and just make it a standard button if you don't plan on actually submitting the form:An alternative method would be to set an
onsubmit
handler on the form: