Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem ze znalezieniem przyczyny odwolywania sie skryptu
Forum PHP.pl > Forum > PHP
rad11
Witam, mam problem z odnalezieniem przyczyny dlaczego skrypt raz wykonuje odwolanie sie do metody poprzez ajax raz a w nie ktorych razach pare razy:

Metoda PHP:
  1. public function executeEditStickyComment(sfWebRequest $request) {
  2. header('Content: application/json');
  3. $query = Doctrine_Query::create()
  4. ->update('StickyHasComments')
  5. ->set('comment', '?' , $_POST['comment'])
  6. ->where('id_sticky_has_comment=?', $_POST['id_sticky_has_comment'])
  7. ->execute();
  8. echo json_encode(true);
  9.  
  10. }


JS:

  1. $('.edit_link').live('click', function(e){
  2.  
  3. var $this = $(this);
  4. var el_id = $this.attr('data-sticky-has-comment-id');
  5. var el_val = $this.parent('.post').find('.post-content').addClass('active-edit').html();
  6. var $el = $('.post-content.active-edit');
  7. var $parent = $this.parent('.post');
  8. var textarea_html = '<textarea class="edit_text_area" id="el_id-'+el_id+'">'+el_val+'</textarea>';
  9.  
  10.  
  11. $el.fadeOut(200, function() {
  12. $('.btn, .statuses').addClass('hide');
  13. $('.ui-dialog-buttonset button, #comment, .statuses').attr('disabled', true);
  14. $this.fadeOut(200, function() {
  15. if ( $('#el_id-'+el_id).length == 0) {
  16. $parent.append(textarea_html);
  17. }
  18. else {
  19. $('.edit_text_area').removeClass('active');
  20. $('#el_id-'+el_id).removeClass('hide').addClass('active').fadeIn();
  21.  
  22. }
  23. if ( $('#save_comment'+el_id).hasClass('hide') ) {
  24. $('#save_comment'+el_id).removeClass('hide');
  25. }
  26.  
  27. if ($('#save_comment'+el_id)) {
  28. $('#save_comment'+el_id).live('click',function(e) {
  29. var comment = $('#el_id-'+el_id).val();
  30.  
  31. $.ajax({
  32. url: "/sticky/EditStickyComment",
  33. data: {
  34. comment: comment,
  35. id_sticky_has_comment: el_id
  36. },
  37. type: "POST",
  38. dataType : "json",
  39. success: function(res) {
  40. $('.post-content.active-edit').text(comment);
  41. $('#save_comment'+el_id).addClass('hide').fadeOut(200, function() {
  42. $this.fadeIn(200);
  43. });
  44. $('#el_id-'+el_id).fadeOut(function() {
  45. $el.fadeIn(200);
  46. });
  47. $('.btn, .statuses').removeClass('hide');
  48. $('.ui-dialog-buttonset button, #comment').attr('disabled', false);
  49. $('.post-content.active-edit').removeClass('active-edit');
  50. $('.ui-dialog-titlebar-close').live('click', function(){
  51. $('.post-content.active-edit').removeClass('active-edit');
  52. $('#edit_comment.active-edit').removeClass('active-edit');
  53. });
  54.  
  55. }
  56. });
  57.  
  58.  
  59.  
  60. e.preventDefault();
  61. })
  62. }
  63.  
  64. });
  65. });
  66.  
  67.  


HTML:
  1. <div class="post-container" style="height: 60%; width:100%; overflow-y: scroll; padding-top: 15px;"><div class="post" style="border-bottom: 1px solid black;margin-bottom: 10px; padding-bottom: 10px;"><span style="width: 100px;" class="post-date">2014-11-24 22:10:20</span> <a class="btn hide" style="color: blue;" id="delete_comment" href="#" data-sticky-has-comment-id="208">usun</a> <a style="color: blue;" class="" id="save_comment208" href="#" data-sticky-has-comment-id="208">zapisz</a> <a style="color: blue; display: inline;" id="edit_comment" href="#" data-sticky-has-comment-id="208" data-username="Administrator" data-user-id="1" data-datetime="2014-11-24 22:10:20" data-comment="159" class="edit_link btn hide">edytuj</a> <i id="fa-check" class="fa fa-check statuses hide" disabled="disabled" style="color: rgb(0, 0, 0);"></i> <i id="fa-exclamation" class="fa fa-exclamation statuses hide" disabled="disabled"></i> <i id="fa-times-circle-o" class="fa fa-times-circle-o statuses hide" disabled="disabled"></i> <p class="post-name">Administrator</p><p class="post-content active-edit" data-sticky-has-comment-id="208" style="display: none;">159adfas123</p><textarea class="edit_text_area active" id="el_id-208" style="display: inline-block;">159</textarea></div></div>
  2.  

Jest cos wedlug was co moze powodowac po jednym kliknieciu wywolanie 2 wywolan ajaxowych i za kazdym razem zwieksza sie o 2 po zmienie pola i kliknieciu zapisz hmmmm
maly_swd
Pewnie po każdym zapisie nakładasz znowu zdarzenia na elementy
rad11
Po zmianie z:

  1. $('#save_comment'+el_id).live('click',function(e)


na

  1. $('#save_comment'+el_id).undind().bind()('click',function(e)


i dodanie w ajaxie

  1. cache: false


chodzi dobrze nie rozumiem tego ale jest ok moze komus sie przyda Pzdr.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.