【发布时间】:2014-01-27 08:21:39
【问题描述】:
我正在使用 Ajax 来动态更新数据表而不刷新。到目前为止我没有问题。用户从 Form 中选择某些标准。问题是,我不再想将内容提取到同一页面,但我想重定向并在不同的模板上加载内容:
用户选择 (Page1.html) -> Ajax -> 重定向到 Page2.html -> 在 Page2 中加载数据
有人可以看看下面的代码并告诉它为什么不工作吗?我可以重定向,但没有任何返回的数据。
Ajax
if (t && e ) {
dataArray = new Array;
dataArray[0] = e;
dataArray[1] = t;
$.ajax({
type: "POST",
url: "includes/filter.php",
data: {
Name: e,
Color: t,
},
success: function (e) {
window.location.href = 'Page2.html'; // Redirect to this page
$("#Wrapper").html(e); // Load content to this page in Div # Wrapper
// If I Uncomment the two lines above and just add $("#table").html(e); it will successfully load content within the table div on the same page
}
});
}
filter.php 处理服务器端查询并输出包含数据的 html 表。 谢谢
【问题讨论】:
-
嗯..一旦到达
window.location.href,它就会重定向到该页面,并且没有数据随之传递。为什么不在重定向时,使用查询来获取该页面上的数据?