0
不知道这是否应该在JavaScript或其他内容中完成。基本上,我有一个小测验类型的东西,所有的问题都在一个页面上。我有一个ajax函数来检查它是什么问题,如果它是最后一个问题,它会将用户重定向到一个新页面,例如JavaScript从网址获取参数
if(totalScore <= 10) {
$.ajax({
method: "POST",
url: "php/handleData.php",
data: { answers: ansArray, page: window.location.href, pt: "aa" }
}).done(function(response) {
window.location.replace("page2.html" + '?le=' + le + '&ch=' + ch);
}).fail(function(jqXHR, textStatus ) {
console.log("Request failed: " + textStatus);
window.location.replace("page2.html" + '?le=' + le + '&ch=' + ch);
});
return false;
}
如您所见,重定向还包括一些附加参数。因此,当我重定向,我在页面上像
page2.html?LE = 1 & CH = 2
现在我不必然需要在这个网址这些PARAMS,但它是我可以考虑让他们转到第2页的唯一方法。第2页有一个按钮就像
<a href="www.link1.com>" target="_blank" class="btn btn-primary" role="button">Visit link1.com ></a>
这是在这个href中,我需要params le和ch被注入。
我该怎么做呢?
感谢
见https://medialize.github.io/URI.js/docs.html#search-set – haim770
那么你可以在'localStorage'中设置'le'和'ch',当你在page2.html中时,可以从那里访问。 –