JQTouch存在问题,其中动画和加载到新的div ID有时发生在地理位置数据准备好和/或对PHP脚本的AJAX请求准备好之前。
我正在尝试收听页面AnimationStart(也尝试过结束,不确定它是否更好?),但它在这个过程中完全破坏了我的代码(没有错误,只是没有运行)。
关于如何在下面的代码中设置我的函数,以便事件侦听器在开始动画之前等待AJAX和地理定位工作,有什么建议吗?
function locationList(clicked_id) {
navigator.geolocation.getCurrentPosition(
function(position) {
$('#location-list').bind('pageAnimationStart', function(event, info){
if (info.direction == 'in')
$.ajax({
beforeSend: function () {
$('#location-list').html('<div class="ajax-load"><img src="img/ajax-loader.gif" /></a>');},
url: 'search.php',
type: 'GET',
data: 'id='+clicked_id+'&action=geolocation&latitude='+position.coords.latitude+'&longitude='+position.coords.longitude,
success: function(msg) {
$('#location-list').html(msg);
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
alert('Error submitting request.');
}
});
}, /* position */
function() {
$('#location-list').html('<div class="toolbar"><h1>GPS Error</h1><a class="back" href="#home">Home</a></div><div class="scroll"><ul class="rounded"><li><p>To take advantage of this app you need the GPS capability of your phone turned on. Please check whether this is turned on or else the app will not work</p></li></ul></div>');
} /* no position so failure */
);/* bind */
}/* position */
); /* navigator.geo */
}
我会尝试在"complete:"而不是"success:"上更改页面,所以获取数据并在"success:"上填充页面,然后在"complety:"上开始转换
更多信息,请访问:http://api.jquery.com/jQuery.ajax/