Javascript 使用jquery在html页面之间传递参数
我有一个包含jquery函数的html页面Javascript 使用jquery在html页面之间传递参数,javascript,jquery,html,Javascript,Jquery,Html,我有一个包含jquery函数的html页面 <script> function loadCustomers() { $.ajax({ type: 'GET', url: 'http://localhost:8080/cache/getCustomers', dataType: 'json', success: function(data) { var rows = [];
<script>
function loadCustomers() {
$.ajax({
type: 'GET',
url: 'http://localhost:8080/cache/getCustomers',
dataType: 'json',
success: function(data) {
var rows = [];
$.each(data,function(id,value) {
rows.push('<tr><td><a href="clientSiteInfo.html?client=">'+id+'</td><td>'+value+'</td></tr>');
});
$('table').append(rows.join(''));
}
});
};
window.onload = loadCustomers;
</script>
函数loadCustomers(){
$.ajax({
键入:“GET”,
网址:'http://localhost:8080/cache/getCustomers',
数据类型:“json”,
成功:功能(数据){
var行=[];
$.each(数据、函数(id、值){
行推送(“”+id+“”+value+“”);
});
$('table').append(rows.join('');
}
});
};
window.onload=loadCustomers;
我已经为每一行链接了另一个html页面。填充每行时,必须将id值传递到clientSiteInfo.html页面
在clientSiteInfo.html页面中,我有另一个类似于上面的jquery函数
<script>
function loadSites() {
$.ajax({
type: 'GET',
url: 'http://localhost:8080/cache/getSite?clientName='+${param.client},
dataType: 'json',
success: function(data) {
var rows = [];
$.each(data,function(id,value) {
rows.push('<tr><td>'+id+'</td><td>'+value.machine+'</td><td>'+value.state+'</td></tr>');
});
$('table').append(rows.join(''));
}
});
};
window.onload = loadSites;
</script>
函数loadSites(){
$.ajax({
键入:“GET”,
网址:'http://localhost:8080/cache/getSite?clientName='+${param.client},
数据类型:“json”,
成功:功能(数据){
var行=[];
$.each(数据、函数(id、值){
行。推送(“”+id+“”+value.machine+“”+value.state+“”);
});
$('table').append(rows.join('');
}
});
};
window.onload=加载站点;
在GET url中,我尝试读取客户机参数。但这并不是从我的第一页开始的
我做错了什么?我寻找简单的解决方案jQuery没有读取url参数的本机方法。但是,javascript工作得很好:
function getParameterByName(name) {
const match = RegExp(`[?&]${name}=([^&]*)`).exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' ') );
}
在您的代码中,您可以将其命名为
getParameterByName('client')
谢谢,但从我的第一个html来看,它似乎没有传递任何客户端值抱歉,我的错误,一个“'