【问题标题】:JQTouch and handling geolocation and dynamic AJAX requests to PHPJQTouch 并处理对 PHP 的地理定位和动态 AJAX 请求
【发布时间】:2012-04-08 14:40:27
【问题描述】:

JQTouch 存在问题,有时在地理定位数据准备好和/或对 PHP 脚本的 AJAX 请求准备好之前,动画和加载到新的 DIV ID 会发生。

我正在尝试收听 pageAnimationStart(也尝试结束,不确定它是否更好?)但它在此过程中完全破坏了我的代码(没有错误,只是不运行)。

关于如何在下面的代码中设置我的函数以便事件侦听器在开始动画之前等待 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 */

    }

【问题讨论】:

    标签: php ajax geolocation jqtouch event-listener


    【解决方案1】:

    我会尝试在“完成:”而不是“成功:”上更改页面,因此获取数据并在“成功:”上填充页面,然后在“完成:”上开始转换

    更多信息请访问:http://api.jquery.com/jQuery.ajax/

    【讨论】: