2011-02-06 77 views
0

我有包含某種形式的模型視圖。當我提交表單時,它會調用ajax函數,並使用php從數據庫獲取一些數據。它不會刷新。它工作正常,但如果我關閉模式並在我提交請求時第二次打開,它將調用ajax函數2次。如果我關閉並重新打開模式視圖3次呼叫。jquery模態查看問題

當我打電話給我的模態視圖時,我在其中包含了新的.php文件。我把我的jquery函數也放在了模態視圖.php文件中。

我每次打開模態視圖時都會添加我的腳本。它會覆蓋或添加兩個相同的腳本嗎?

這是我的.js功能

$('#contentArea #shareButton').click(function(){ 

     var a = $("#watermark").val(); 
     if(a != "What's on your mind?") 
     { 
      $.post("lib/actions/posts.php?value="+a, { 

      }, function(response){ 

       $('#posting').prepend($(response).fadeIn('slow')); 
       $("#watermark").val("What's on your mind?"); 
      }); 
     } 
    }); 


    $('.commentMark').livequery("focus", function(e){ 

     var parent = $(this).parent(); 
     $(".commentBox").children(".commentMark").css('width','320px'); 
     $(".commentBox").children("a#SubmitComment").hide(); 
     $(".commentBox").children(".CommentImg").hide();    

     var getID = parent.attr('id').replace('record-','');   
     $("#commentBox-"+getID).children("a#SubmitComment").show(); 
     $('.commentMark').css('width','300px'); 
     $("#commentBox-"+getID).children(".CommentImg").show();   
    }); 

    //showCommentBox 
    $('a.showCommentBox').livequery("click", function(e){ 

     var getpID = $(this).attr('id').replace('post_id',''); 

     $("#commentBox-"+getpID).css('display',''); 
     $("#commentMark-"+getpID).focus(); 
     $("#commentBox-"+getpID).children("img.CommentImg").show();   
     $("#commentBox-"+getpID).children("a#SubmitComment").show();   
    }); 

    //SubmitComment 
    $('a.comment').livequery("click", function(e){ 

     var getpID = $(this).parent().attr('id').replace('commentBox-','');  
     var comment_text = $("#commentMark-"+getpID).val(); 

     if(comment_text != "Write a comment...") 
     { 
      $.post("lib/actions/add_comment.php?comment_text="+comment_text+"&post_id="+getpID, { 

      }, function(response){ 

       $('#CommentPosted'+getpID).append($(response).fadeIn('slow')); 
       $("#commentMark-"+getpID).val("Write a comment...");      
      }); 
     } 

    }); 

    //more records show 
    $('a.more_records').livequery("click", function(e){ 

     var next = $(this).attr('id').replace('more_',''); 

     $.post("lib/actions/posts.php?show_more_post="+next, { 

     }, function(response){ 
      $('#bottomMoreButton').remove(); 
      $('#posting').append($(response).fadeIn('slow')); 

     }); 

    }); 

    //deleteComment 
    $('a.c_delete').livequery("click", function(e){ 

     if(confirm('Are you sure you want to delete this comment?')==false) 

     return false; 

     e.preventDefault(); 
     var parent = $(this).parent(); 
     var c_id = $(this).attr('id').replace('CID-',''); 

     $.ajax({ 

      type: 'get', 

      url: 'lib/actions/delete_comment.php?c_id='+ c_id, 

      data: '', 

      beforeSend: function(){ 

      }, 

      success: function(){ 

       parent.fadeOut(200,function(){ 

        parent.remove(); 

       }); 

      } 

     }); 
    }); 

    /// hover show remove button 
    $('.friends_area').livequery("mouseenter", function(e){ 
     $(this).children("a.delete").show();  
    }); 
    $('.friends_area').livequery("mouseleave", function(e){ 
     $('a.delete').hide(); 
    }); 
    /// hover show remove button 


    $('a.delete').livequery("click", function(e){ 

    if(confirm('Are you sure you want to delete this post?')==false) 

    return false; 

    e.preventDefault(); 

    var parent = $(this).parent(); 

    var temp = parent.attr('id').replace('record-',''); 

    var main_tr = $('#'+temp).parent(); 

     $.ajax({ 

      type: 'get', 

      url: 'lib/actions/delete.php?id='+ parent.attr('id').replace('record-',''), 

      data: '', 

      beforeSend: function(){ 

      }, 

      success: function(){ 

       parent.fadeOut(200,function(){ 

        main_tr.remove(); 

       }); 

      } 

     }); 

    }); 

    $('textarea').elastic(); 

    jQuery(function($){ 

     $("#watermark").Watermark("What's on your mind?"); 
     $(".commentMark").Watermark("Write a comment..."); 

    }); 

    jQuery(function($){ 

     $("#watermark").Watermark("watermark","#369"); 
     $(".commentMark").Watermark("watermark","#EEEEEE"); 

    }); 

    function UseData(){ 

     $.Watermark.HideAll(); 

     //Do Stuff 

     $.Watermark.ShowAll(); 

    } 

回答

0

你創建每個調用它的模式的看法?您可能想要重複使用,因爲它會像創建多次那樣接縫,然後將其全部提交。

+0

每次我刪除所有的div元素,當我點擊照片時,我再次創建它們。因爲我調用的函數從數據庫中獲取新聞。當用戶打開模態視圖時,我應該顯示新數據 – Ercan 2011-02-06 10:21:37