ajax 代码包含 "PHP site_url",参数在 ajax 中
ajax code contains "PHP site_url" with parameters in ajax
想问一下,如果ajax代码中包含“PHPsite_url”和中的参数ajax
这是具体代码:
"<a class='btn btn-info' href="<?php 'echo site_url("data_detail/detail_datas/vieworc/ " + item.NIK + "); '?>">Detail</a>"
这是完整代码:
.done(function(dt){
if(dt != null){
console.log(dt)
table.rows().remove().draw();
$.each(dt, function(i, item){
table.row.add([
item.Name,
item.NIK,
item.gender,
item.PositionDesc,
item.Shift,
item.tgl,
item.Attendance,
"<a class='btn btn-info' href="<?php 'echo site_url("data_detail/detail_datas/vieworc/ " + item.NIK + "); '?>">Detail</a>"
]).draw();
})
}
})
});
如果您的 site_url()
只连接字符串,您可以这样做:
// Pass the result as a js variable
const siteUrlTpl = "<?php echo site_url('data_detail/detail_datas/vieworc/{NIK}'); ?>";
// ...
.done(function(dt){
if(dt != null){
console.log(dt)
table.rows().remove().draw();
$.each(dt, function(i, item){
table.row.add([
item.Name,
item.NIK,
item.gender,
item.PositionDesc,
item.Shift,
item.tgl,
item.Attendance,
// Replace the {NIK} to the real value
"<a class='btn btn-info' href='" + siteUrlTpl.replace('{NIK}', item.NIK) + "'>Detail</a>"
]).draw();
})
}
})
请试试这个
"<button type='button' class='btn btn-success' onclick='showDetail(\""+ item.NIK + "\");' >Detail</button>"
想问一下,如果ajax代码中包含“PHPsite_url”和中的参数ajax
这是具体代码:
"<a class='btn btn-info' href="<?php 'echo site_url("data_detail/detail_datas/vieworc/ " + item.NIK + "); '?>">Detail</a>"
这是完整代码:
.done(function(dt){
if(dt != null){
console.log(dt)
table.rows().remove().draw();
$.each(dt, function(i, item){
table.row.add([
item.Name,
item.NIK,
item.gender,
item.PositionDesc,
item.Shift,
item.tgl,
item.Attendance,
"<a class='btn btn-info' href="<?php 'echo site_url("data_detail/detail_datas/vieworc/ " + item.NIK + "); '?>">Detail</a>"
]).draw();
})
}
})
});
如果您的 site_url()
只连接字符串,您可以这样做:
// Pass the result as a js variable
const siteUrlTpl = "<?php echo site_url('data_detail/detail_datas/vieworc/{NIK}'); ?>";
// ...
.done(function(dt){
if(dt != null){
console.log(dt)
table.rows().remove().draw();
$.each(dt, function(i, item){
table.row.add([
item.Name,
item.NIK,
item.gender,
item.PositionDesc,
item.Shift,
item.tgl,
item.Attendance,
// Replace the {NIK} to the real value
"<a class='btn btn-info' href='" + siteUrlTpl.replace('{NIK}', item.NIK) + "'>Detail</a>"
]).draw();
})
}
})
请试试这个
"<button type='button' class='btn btn-success' onclick='showDetail(\""+ item.NIK + "\");' >Detail</button>"