编写我的第一个 JQTouch 应用程序。当我从#login
to 开始时#home
,JSON ajax 调用成功发生,但pageAnimationEnded
事件似乎处于无限循环中。
$(function(){
$('#login').ajaxComplete(function (e, xhr, settings) {
jQT.goTo('#home', 'flip');
});
$('#home').bind('pageAnimationEnd', function(e, info){
alert('animation ended'); //infinite loop happens in here
$.getJSON('/test', function(data) {
alert('json: ' + data); //this returns data successfully
});
});
});
JQuery 拦截并转换为 AJAX 的登录 POST 调用:
<div id="login" class="current">
<div class="toolbar">
<h1>testapp</h1>
<a class="button slideup" id="infoButton" href="#about">About</a>
</div>
<form:form commandName="user" action="/login/authenticate">
<ul class="edit rounded">
<li><form:input path="email"/></li>
<li><form:password path="password" /></li>
<li>Remember Me<span class="toggle"><input type="checkbox" /></span></li>
</ul>
<a style="margin:0 10px;color:rgba(0,0,0,.9)" href="" class="submit whiteButton">Login</a>
</form:form>
</div>
任何提示将不胜感激,在此先感谢!:-)
更新
显然 .ajaxComplete 也接收其他元素的事件。我添加了一个守卫来过滤我想要的事件:
$(document).ready(function(e){
alert('document ready');
$('#login').ajaxComplete(function (e, xhr, settings) {
if(settings.url == '/login/authenticate') { //add check to prevent infinite loop
alert('jqt goto ' + settings.url);
jQT.goTo('#home', 'flip');
}
});
$('#home').bind('pageAnimationEnd', function(e, info){
alert('animation ended');
$.getJSON('/test', function(data) {
alert('json: ' + data);
});
});
});