2012-02-02 69 views
1

我正在開發一個使用jQuery Mobile,Phonegap的應用程序。Ajax請求GET查詢字符串參數不能動態配置

下面我從遠程服務器上的數據作爲JSON

function requestFunc() { 
    var el, li, i; 

    $.ajax({ 
     type: 'GET', 
     url: "http://mobil.myservice.org/getpanodata.php", 
     data: 'page=2', 
     dataType: 'jsonp', 
     success: function(json_results) { 
       //something listing etc... 
      } 
     }); 
} 

的功能工作的功能。但我想動態配置頁面參數。所以我試圖改變這個代碼爲

function requestFunc() { 
     var el, li, i; 

     $.ajax({ 
      type: 'GET', 
      url: "http://mobil.myservice.org/getpanodata.php", 
      data: 'page=' + paramPage, 
      //the changes 
      dataType: 'jsonp', 
      success: function(json_results) { 
       //something listing etc... 
      } 
     }); 
} 

但這次功能不起作用。我怎樣才能動態地配置頁面的GET字符串。

回答

2

你可以嘗試將數據發送的

function requestFunc() { 
    var el, li, i; 
    var dataObj = {page : paramPage}; /* change made here */ 
    $.ajax({ 
     type: 'GET', 
     url: "http://mobil.myservice.org/getpanodata.php", 
     data: dataObj, /* change made here */ 
     //the changes 
     dataType: 'jsonp', 
     success: function(json_results) { 
      //something listing etc... 
     } 
    }); 
} 

jQuery的阿賈克斯()頁面給出了相同的here

+0

一個很好的例子呀,數據將被傳遞中作爲一個數組,而不是一個字符串。 jQuery然後將其轉換爲URL參數。 – Danack 2012-02-02 05:43:11

+0

Woww完美;)它的作品:) – 2012-02-02 17:26:18