簡體   English   中英

AJAX未在對話框按鈕上運行單擊

[英]AJAX Not Running On Dialog Box Button Click

我想知道是否有人可以幫助我。

首先,道歉,因為我才剛剛開始使用Javascript,所以我也許正在犯一個非常基本的錯誤,所以請多多包涵。

我試圖實施Example 2 ,從這個片的第三方軟件在我的畫廊頁面顯示在這里

如下面的代碼所示,我已經能夠將消息添加到onclick事件中,即當用戶單擊“ bin”圖標時,但是應該在單擊“ Delete”按鈕時運行的AJAX代碼段是失敗:

<script type="text/javascript"> 

    Galleria.ready(function() {
        this.$('thumblink').click();

    $(".galleria-image").append( 
    "<span class='btn-delete ui-icon ui-icon-trash'></span>"); 
    $(".btn-delete").live("click", function(){
    $.msgbox("You are about to delete this image. It cannot be restored at a later date. Do you wish to continue?", {
    type: "alert",
      buttons : [
        {type: "submit", value: "Delete"},
        {type: "cancel", value: "Cancel"}
      ]
      },function(Delete) {
      var img = $(this).closest(".galleria-image").find("img"); 
      // send the AJAX request
      $.ajax({
        url : 'delete.php',
        type : 'post',
        data : { image : img.attr('src'),  userid: "VALUE", locationid: "VALUE"},
        success : function(){
        img.parent().fadeOut('slow');
    }
    });               
    });
    return false;
    });     
    });

</script>

盡管花了一些時間檢查代碼,但我真的不確定在哪里出錯了。 我只是想知道是否有人可以看看這個,然后讓我知道我哪里出了問題。

更新后的工作解決方案

<script type="text/javascript"> 

        Galleria.ready(function() {
            this.$('thumblink').click();

        $(".galleria-image").append( 
        "<span class='btn-delete ui-icon ui-icon-trash'></span>"); 
        $(".btn-delete").live("click", function(){  
        var img = $(this).closest(".galleria-image").find("img"); 
        $.msgbox("You are about to delete this image. It cannot be restored at a later date. Do you wish to continue?", {
        type: "alert",
          buttons : [
            {type: "submit", value: "Delete"},
            {type: "cancel", value: "Cancel"}
          ]
          },
          function(result) {
          if(result)

          // send the AJAX request
          $.ajax({
            url : 'delete.php',
            type : 'post',
            data : { image : img.attr('src'),  userid: "VALUE", locationid: "VALUE"},
            success : function(){
            img.parent().fadeOut('slow');

    }
        });               
        });
        return false;
        });     
        });

    </script>

非常感謝和問候

看來, this在MSGBOX回調是不是一個元素(換句話說,在img變量是一個空數組。盡量把var img聲明右轉入的onclick監聽器。

$(".btn-delete").live("click", function(){
var img = $(this).closest(".galleria-image").find("img");

有幫助嗎?

我已將變量Delete重命名為result

function(result) {
  //result variable holds the value of what user clicks 'Delete' or 'Cancel'. 
  //Cancel click will pass false.
  //Delete click will pass Delete.
  alert(result)
  //You can also check if(result=='Delete') instead of if(result)
  if(result)
  {
      var img = $(this).closest(".galleria-image").find("img"); 
      // send the AJAX request
      $.ajax({
        url : 'delete.php',
        type : 'post',
        data : { image : img.attr('src'),  userid: "VALUE", locationid: "VALUE"},
        success : function(){
        img.parent().fadeOut('slow');
    }
  }

看看是否可行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM