0

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. 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. 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. 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.

Anyway I can adjust my javascript code to fix this?

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);
Luminous
  • 1,771
  • 2
  • 24
  • 43

2 Answers2

0

Rather than using a href attribute, bind a click event to the anchor tag and call the URL you want freely!

href is always a danger, due to its relative path logic.

buræquete
  • 14,226
  • 4
  • 44
  • 89
0

I found you can make links relative to root

Having links relative to root?

Adding \ to assets/details/?id= fixes my issues.

Community
  • 1
  • 1
Luminous
  • 1,771
  • 2
  • 24
  • 43