2012-02-02 67 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