Get two variable inside the URL (JS)

时间:2019-01-07 13:38:37

标签: javascript jquery html datatables

I want to get two variable inside my URL window.location = "viewticket.html?ticketnumber=" + ticketnumber + "&timeofpurchase=" + (the value here). Now, i am able to get one variable in which is the ticketnumber, i want to get timeofpurchase in also. How can i do? I am using JS to code.

for (var i = 0; i < arr.length; i++) {
  t.row.add([
    arr[i].eventname,
    arr[i].number,
    arr[i].timeofpurchase,
    "<a href='#' class='btn btn-secondary " + arr[i].eventstatus + "' 
    style = 'background: green; color: white;'
    id = 'btn" + arr[i].ticketnumber + "' >
    View < /a>"
  ]).draw(false);

  // call the view button of the datatable
  $("#adminorder").on("click", "#btn" + arr[i].ticketnumber, {
    id: arr[i].ticketnumber
  }, function(event) {
    var data = event.data;
    getdetails(data.id);
  });

}
$("#adminorder").show();
}

// call the show user
function getdetails(ticketnumber) {
  window.location = "viewticket.html?ticketnumber=" + ticketnumber + "&timeofpurchase=" + (the value here);
}

2 个答案:

答案 0 :(得分:0)

Make the following changes below:

This is an example of event delegation so you can avoid putting click function inside for loop.

"<a href='#' class='btn btn-secondary " + arr[i].eventstatus + "' 
        style = 'background: green; color: white;'
        id = '"+ arr[i].ticketnumber+"' data-time='"+arr[i].timeofpurchase+"'>
        View < /a>"

$("body").on("click", "#adminorder a", function(){
     var id = $(this).attr("id");
     var timeOfPurchase = $(this).attr("data-time");
     getDetails(id, timeOfPurchase);
});

答案 1 :(得分:0)

正在工作的朋克是here。如果这样可以解决您的问题,请标记我的答案。