【问题标题】:Appending Jquery Var to a function URL将 Jquery Var 附加到函数 URL
【发布时间】:2017-01-11 05:11:43
【问题描述】:

这里我想将变量 arr_icao 和 dep_icao 附加到 url

var arr_icao = document.getElementById("arr_icao").value;
var dep_icao = document.getElementById("dep_icao").value;

$.ajax({
    type: 'POST',
    url: "http://localhost/position/route_finder/" + arr_icao + dep_icao,
    success: function (data) {
        $(".route-results").html(data);
    }
});

【问题讨论】:

  • 是什么阻碍了您实现这一目标?

标签: php html ajax codeigniter


【解决方案1】:

你可以像这样使用它

var newUrl = "http://localhost/position/route_finder/" + arr_icao +"" + dep_icao;
$.ajax({
    type: 'POST',
    url: newUrl,
    success: function(data) {
        $(".route-results").html(data);
    }
});

【讨论】:

    【解决方案2】:

    改变

    url: "http://localhost/position/route_finder/" + arr_icao + dep_icao,
    

    url: "http://localhost/position/route_finder/" + arr_icao + "/" + dep_icao,
    

    【讨论】:

      【解决方案3】:

      如果 route_finder 是一个有 2 个参数的函数,那么你应该使用

      "http://localhost/position/route_finder/" + arr_icao + "/" + dep_icao,
      

      如果您要使用GET 方法获取数据,请使用

      "http://localhost/position/route_finder?arr_icao="+arr_icao+"&dep_icao="+dep_icao,
      

      正如你定义的方法 post 你应该去

      "http://localhost/position/route_finder/" + arr_icao + "/" + dep_icao,
      

      【讨论】:

        【解决方案4】:

        您可以使用 ? 继续在 URL 的末尾添加参数?

        如果是 GET 请求

        "http://localhost/position/route_finder/?arr_ica="+arr_icao+"&dep_icao="+dep_icao,

        或者如果它是一个 POST 请求

        "http://localhost/position/route_finder/"+arr_icao+"/"+dep_icao
        

        【讨论】:

          猜你喜欢
          • 2011-09-28
          • 1970-01-01
          • 2015-04-22
          • 1970-01-01
          • 2012-12-14
          • 2015-12-23
          • 2013-12-18
          • 1970-01-01
          • 2017-04-30
          相关资源
          最近更新 更多