簡體   English   中英

JQTouch並處理對PHP的地理位置和動態AJAX請求

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

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 */

    }

我會嘗試更改“ complete:”上的頁面,而不是“ success:”上的頁面,因此獲取數據並在“ success:”上填充頁面,然后在“ complete:”上開始過渡

有關更多信息,請訪問: http : //api.jquery.com/jQuery.ajax/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM