Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. success: function(response) {
  2. if(response.success == 1) {
  3. alert('success');
  4. if(typeof $row == 'undefined' ) {
  5. alert('undefined!'); // this alert does not come up
  6. } else {
  7. alert('the $row var is defined'); // this alert DOES come up
  8. $row.html('hahaha'); // this works, the contents of the row are replaced
  9. $row.remove(); // this doesn't work. The row is still there, with 'hahaha'
  10. }
  11. } else {
  12. alert('failed');
  13. }
  14. }
  15.  
  16. $(document).on("click",".allowed_val_delete",function() { // 20150328
  17. var $this_row = $(this).closest('tr');
  18. var allowed_val_id = $this_row.attr("id").split('_')[1];
  19. var data = new Object();
  20. //alert('Delete allowed value with id "' + allowed_val_id + '"');
  21. data.action = 'DELETE';
  22. data.id = parseInt(allowed_val_id,10);
  23. $this_row.hide(); // hide row immediately. Show it again if ajax fails.
  24.  
  25. $.ajax({
  26. data: data,
  27. //type: "POST",
  28. type: "POST", // 20150502 experimenting with other HTTP methods. (method is alias for type but requies jquery 1.9+)
  29. url: "controllers/core_fields/ajax/allowed_values.php",
  30. dataType: "json",
  31. success: function(response) {
  32. if(response.success == 1) {
  33. //alert('Removing row');
  34. if(typeof $this_row == 'undefined') {
  35. alert('$this_row with val_id = ' + allowed_val_id + ' is undefined');
  36. } else {
  37. //alert('$this_row with val_id = ' + allowed_val_id + ' is defined');
  38. $this_row.remove(); // doesn't work
  39. }
  40. /*var index = allowed_value_ids.indexOf(allowed_val_id);
  41. allowed_value_ids.splice(index,1); // remove from the list of ids*/
  42. $("#maintable").tablesorter().trigger("update"); // updates sorting
  43. $("#maintable").tablesorter().trigger("appendCache"); // updates sorting
  44. } else {
  45. alert('Failed to remove');
  46. $this_row.show();
  47. }
  48. //alert('action: ' + response.action + '; id: ' + response.id);
  49. //alert(response);
  50. }
  51. });
  52.  
  53. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement