Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have displayed data in html table by using java script and web-services. i add two more columns edit and delete by taking button. now if i click on edit button page should redirect to edit page by selecting that row's id and display data on redirected page.

What I have tried:



$(document).ready(function () {

$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "EmployeeView.aspx/Binddatatable",
data: "{}",
dataType: "json",

success: function (data) {

//$("#empdata > tbody > tr").remove();
// $("#empdata").append("<tbody>");
for (var i = 0; i &lt; data.d.length; i++) {
$("#empdata").append("<tr><td>" + data.d[i].EmpId + "</td><td>" + data.d[i].EmpName + "</td><td>" + data.d[i].Password + "</td><td>" + data.d[i].Email + "</td><td>" + data.d[i].MobileNo_O + "</td><td>" + data.d[i].MobileNo_P + "</td><td>" + data.d[i].UserType + "</td><td>" + data.d[i].BranchName + "</td>" + '<td style="width:25"><button type="button" id="btnview" class="btn btn-info searchData" onclick="myFunction(' + data.d[i].EmpId + ')"><span class="glyphicon glyphicon-user"></span>Edit Details</button></td>'+ "</tr>");

// $("#empdata").tablesorter({ widgets: ['zebra'] });
// alert(JSON.stringify(data));
}
},
error: function (result) {
alert("Error");
}
});
// return false;
});



function myFunction(EmpId) {

$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "EmployeeView.aspx/EditDetails",
dataType: "json",
data: "{ 'ID': '" + EmpId + "' }",

success: function (data) {
window.location.href="/KB/answers/EmployeeEdit.aspx";
}

},
failure: function (data) {
alert(99);
alert("fail");

}
});
}
Posted
Updated 20-Jun-18 1:11am
Comments
F-ES Sitecore 20-Jun-18 5:44am    
Why don't you just do

window.location.href="EmployeeEdit.aspx?id=" + EmpId;

Or don't use ajax at all. Doing an ajax call then doing a redirect on success is kinda pointless.

1 solution

Why dont you make it a link style it to appear like a button which points to the needed page with query string of the employee id. And if need add this attribute to the link target='_blank'

Something like this

HTML
+"<td><a id=''+ data.d[i].EmpId + '' src='EmployeeEdit.aspx?id=" +  data.d[i].EmpId +' target='_blank'>Edit</a></td>"
+"<td><a id=''+ data.d[i].EmpId + '' src='EmployeeView.aspx?id=" +  data.d[i].EmpId +' target='_blank'>View</a></td>"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900