[英]How to prevent href link from directing to controller name in url bar and go to controller specified in href tag
I'm allowing a user to assign a computer to a software license and I use ajax to pop up a modal to facilitate that assignment. 我允许用户将计算机分配给软件许可证,并且我使用ajax弹出模式来促进该分配。 After the ajax completes I use javascript to create a href tag using the returned id(s) to create a link and I add it to the table showing the assigned computers.
ajax完成后,我使用javascript使用返回的id创建一个href标签来创建链接,然后将其添加到显示分配的计算机的表中。 The links on page refresh or when you go there show as
localhost:8080/assets/details/?id=510
, but the links being created by javascript are coming out as localhost:8080/licenses/details/asseets/details/?id=510
. 页面刷新或您去那里时的链接显示为
localhost:8080/assets/details/?id=510
,但由javascript创建的链接显示为localhost:8080/licenses/details/asseets/details/?id=510
。 The URL bar at the top is localhost:8080/licenses/details/?licenseid=80
so that's why the javascript created ones are directing to the licenses controller instead of the assets controller. 顶部的URL栏是
localhost:8080/licenses/details/?licenseid=80
因此这就是JavaScript创建的代码将直接定向到许可证控制器而不是资产控制器的原因。
Anyway I can adjust my javascript code to fix this? 无论如何,我可以调整我的JavaScript代码来解决此问题?
success: function (data) {
for (var i = 0; i < data.length ; i++) {
var row = [
'<input value="'+data[i].id+'" />'
, '<a href="assets/details/?id=' + data[i].id + '">' + data[i].name
, data[i].manufacturerItem.serialNumber];
table.fnAddData(row);
Rather than using a href attribute, bind a click event to the anchor tag and call the URL you want freely! 与其使用href属性,不如将click事件绑定到锚标记并自由调用您想要的URL!
href is always a danger, due to its relative path logic. href由于其相对路径逻辑而总是很危险。
I found you can make links relative to root 我发现你可以建立相对于根的链接
Having links relative to root? 有相对于根的链接?
Adding \\
to assets/details/?id=
fixes my issues. 在
assets/details/?id=
添加\\
可以解决我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.