Guest User

Untitled

a guest
Jan 16th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. $(document).ready(function() {
  2.  
  3. $("#mydiv table tbody td").click(function() {
  4. alert("You clicked my <td>!" + $(this).html() +
  5. "My TR is:" + $(this).parent("tr").html());
  6. });
  7.  
  8.  
  9.  
  10. $('#myform').submit(function()
  11. {
  12. try {
  13. var host = $("#host").val();
  14. var port = $("#port").val();
  15. var username = $("#username").val();
  16. var password = $("#password").val();
  17. var database = $("#database").val();
  18.  
  19. $.ajax({
  20. type: "POST",
  21. url: "/management/connectDatabase",
  22. dataType: "JSON",
  23. data: "host="+host+"&port="+port+"&username="+username+"&password="+password+"&database="+database,
  24. cache: false,
  25. success:
  26. function(data){
  27. $('#mydiv').html(show_tables(data));
  28. },
  29. });
  30. return false;
  31. }
  32.  
  33. catch(e){
  34. console.debug(e);
  35. }
  36. });
  37. });
  38.  
  39. function show_tables(data)
  40. {
  41. var html = '<div id="mydiv">';
  42.  
  43. html += '<table class="display" id="example">';
  44. html += '<thead><tr><th>Tables</th></tr></thead><tbody>';
  45. for (var tablesCount = 0; tablesCount < data.tables.length; tablesCount++){
  46. html += '<tr class=gradeA id="trtest">';
  47. html += '<td id="tdtest">' + data.tables[tablesCount] + '</td>';
  48. html += '</tr>';
  49. }
  50. html += '</tbody></table>';
  51.  
  52. html += '</div>';
  53. return html;
  54. }
  55.  
  56. $("#mydiv table tbody").on('click', 'td', function() {
  57. alert("You clicked my <td>!" + $(this).html() +
  58. "My TR is:" + $(this).parent("tr").html());
  59. });
  60.  
  61. $("#mydiv table tbody").on('click', 'td', function() {
  62. alert("You clicked my <td>!" + $(this).html() + "My TR is:" + $(this).parent("tr").html());
  63. });
  64.  
  65. $.post('ajax/test.html', function(data) {
  66. $('.result').html(data);
  67. // Add .click code here
  68. });
Add Comment
Please, Sign In to add comment