jQuery Ajax Request GET 查询字符串参数不能动态配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9107591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 10:20:16  来源:igfitidea点击:

Ajax Request GET query string parameters cannot be configured dynamically

jqueryajaxjquery-mobile

提问by Erhan H.

I'm developing an application using jQuery Mobile, Phonegap.

我正在使用 jQuery Mobile、Phonegap 开发应用程序。

The function below I get data from remote server as JSON

下面的函数我从远程服务器获取数据作为 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...
           }
      });
}

The function works. But i want to config page parameter dynamically. So i tried to change this code as

该功能有效。但我想动态配置页面参数。所以我尝试将此代码更改为

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...
           }
       });
 }

but this time function is not working. How can I configure page GET string dynamically.

但这次功能不起作用。如何动态配置页面 GET 字符串。

回答by frictionlesspulley

you could try to send the data as

您可以尝试将数据发送为

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...
       }
   });
}

The JQuery ajax() page gives a good example for the same here

JQuery ajax() 页面在这里给出了一个很好的例子