2012-04-02 64 views
0

我必須使用PhoneGap的1.5.0和jQuery移動1.1.0 .... 做我有這樣Web服務不叫第二次,如果我提出請求到web服務器

<div data-role="page" id="page1">  
</div> 

<div data-role="page" id="page2">  
</div> 
結構的應用

我呼籲第2頁的頁面顯示一個Web服務這樣的

$("#page2").on("pageshow", function(e) { 
$ 
    .ajax({ 
     type : 'GET', 
     url : "http://192.168.1.88:9051/some.xml" 
       + "?time=" + Date.now(), 
     data : { 
      key : "value" 
     }, 
     dataType : "xml", 
     success : function(xml) { 

     }, 

     error : function(xhr) { 
      alert("Error while loading the Mock Service !!!"); 
     } 
    }); 
}); 

,如果我是第一次到第二頁輸入這工作得很好。假設如果我導航回到page1,然後再回到Page2,那麼Web服務不會被調用。

我甚至用pageinit嘗試過,它沒有工作......這是一些Ajax問題?

如何糾正?

+0

http://stackoverflow.com/questions/5622581/jquery-mobile-document-ready-equivalent要求使用pagebeforeshow。 – ganeshran 2012-04-02 06:44:12

回答

2

您是否試過關閉緩存?

// setup globally 
$.ajaxSetup ({ 
    cache: false 
}); 

或者,

// setup individual calls 
$.ajax({ 
    cache: false, // disable caching 
    type : 'GET', 
    url : "http://192.168.1.88:9051/some.xml" 
      + "?time=" + Date.now(), 
    data : { key : "value"}, 
    dataType : "xml", 
    success : function(xml) { 

    }, 

    error : function(xhr) { 
     alert("Error while loading the Mock Service !!!"); 
     } 
    }); 
}); 
+0

在哪裏可以做到這一點? – 2012-04-02 06:46:58

+0

您可以在$(function(){})中的任何位置聲明它; – 2012-04-02 06:53:27

+0

它仍然沒有工作......如果我們隱藏它,我們可以刪除該頁面嗎? – 2012-04-02 07:00:08

0

你使用Firebug檢查時,「控制檯」和「網絡」選項卡,看看你的腳本發送和接收?

$("#div") 

對我來說看起來不對。應該是div(所有div元素)或#page1(id'page1')

+0

我將此ID更改爲'div'作爲此問題..我的ID僅爲'page1'... – 2012-04-02 06:46:25