【发布时间】:2016-06-02 17:46:43
【问题描述】:
我有一个页面,其中包含我构建的一些链接,这些链接调用了 Web 服务。
这是jquery函数的摘录:
$.ajax({
type: 'GET',
dataType: 'json',
url: 'json.php',
success: function (response) {
data = response.obj;
var errorCode = response.errorCode;
if (errorCode === 200) {
$.each(data, function (key, value) {
l_id_nation = value.id;
var name = value.name;
var continente = name.val;
$('#sidemenu').append('<li><a class="id_continent" href="javascript:void(0)">' + continente + '</a></li>');
});
$('.id_continent').click(function () {
var id_continent = $(this).html();
});
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
点击后,我会打开一个显示一些信息的页面。
页面的url是/trip.php?id_trip=1234&continet=oceania
我想要一个类似/trip/123/oceania的网址
我正在考虑创建一个路由文件,但我不明白如何动态创建这个新 url。
【问题讨论】:
-
ajax 函数似乎独立于所需的 url 结构 - 或者是
"url of the page"您引用了您在 ajax 中生成的链接的 href - 抱歉,有点不清楚 -
在响应客户端之前,您需要在服务 api 中处理生成的 url。这种方式使您的 url 与客户端和服务器同步。而且您只管理服务器中的所有内容
-
你应该在你的 json.php 中返回一个友好的 url 并在你的 javascript 客户端的应用程序中使用它。