【问题标题】: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