简体   繁体   English

JQTouch并处理对PHP的地理位置和动态AJAX请求

[英]JQTouch and handling geolocation and dynamic AJAX requests to PHP

Having an issue with JQTouch where the animation and load to a new DIV ID sometimes occurs before either the geolocation data is ready and/or the AJAX request to a PHP script is ready. JQTouch存在一个问题,即在准备好地理位置数据和/或准备好对PHP脚本的AJAX请求之前,有时会发生动画并加载到新的DIV ID的情况。

I'm attempting to listen to the pageAnimationStart (tried end too, not sure whether it is better?) but it's completely breaking my code in the process (no errors, just doesn't run). 我试图收听pageAnimationStart(也尝试结束,不确定是否更好吗?),但它在此过程中完全破坏了我的代码(没有错误,只是没有运行)。

Any suggestions on how to set up my functions in the code below so that the event listener waits for the AJAX and geolocation to work, before starting the animation? 关于如何在下面的代码中设置我的函数的任何建议,以便事件监听器在开始动画之前等待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 */

    }

I would try to change the page on "complete:" instead of on "success:", so get the data and fill the page on "success:" then start the transition on "complete:" 我会尝试更改“ complete:”上的页面,而不是“ success:”上的页面,因此获取数据并在“ success:”上填充页面,然后在“ complete:”上开始过渡

more info at: http://api.jquery.com/jQuery.ajax/ 有关更多信息,请访问: http : //api.jquery.com/jQuery.ajax/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM