因为我从你的问题行了解 - “我会再切换到另一个网页非常相同的HTML文档中,并显示‘你的消息已发送’。 “ - 除了卫生署...的答案,如果你想要去到另一页上的成功ajax调用之前您序列化表单数据后添加此
var goto=$('#yourFormId').attr('href')
,并在随后成功回调使用goto
。 。
success: function()
{
//at the end include this:
location.href=goto;
}
注:你可以将任何地址分配给goto
,在成功的时候打开地址
为JQM多页面结构,你可以触发AJAX的单击事件成功。假设你在你的html页面中有这个。
<div data-role="page" id="page-one" data-title="Page 1">
<div data-role="header">
<h1>Page 1</h1>
</div>
<div data-role="content">
<p>Body copy for page 1</p>
<p><a href="#page-two" id="toPage2">Link to page 2</a></p>
</div>
<div data-role="footer">
Copyright
</div>
</div>
<div data-role="page" id="page-two" data-title="Page 2">
<div data-role="header">
<h1>Page 2</h1>
</div>
<div data-role="content">
<p>Body copy for page 2</p>
<a href="#page-one" id="toPage1">Link to page 1</a>
</div>
<div data-role="footer">
Copyright
</div>
</div>
而且成功要打开Page 2
id为page-two
。现在的Page 2
链接是在div Page 1
的<a>
标签。所以最后,而不是在阿贾克斯成功回调使用location.href
你可以使用jQuery .trigger()
success: function()
{
$('a#toPage2').trigger('click',function(){})
}
来源
2013-10-17 07:46:58
UDB
http://stackoverflow.com/questions/16323360/submitting-html-form-using-jquery-ajax –
jQuery的['。 submit()'](http://api.jquery.com/submit/)和['$ .ajax()'](http://api.jquery.com/jQuery。ajax /)函数应该让你开始。 –
@你链接到的例子不是我期待的,因为它转换到另一个网址。我想保持在同一个网址,因为jquery-mobile文档可以有多个页面:jquerymobile.com/demos/1.2.1/docs/pages/multipage-template.html – Baz