2016-10-17 39 views
1

我想獲得一個彈出提交按鈕的工作,但我還沒有找到我正在尋找的解決方案。WordPress的 - 模態彈出提交確認

我使用jquery modal插件在提交之前向客戶端顯示其更改的內容。但是,當我嘗試提交時,沒有任何反應。彈出提交按鈕,而.modify按鈕是打開它的按鈕。我沒有彈出自己的問題。

我的控制檯測試正在打印,所以我知道我的事件監聽器沒有問題。也許它與event.preventDefault()有關?

在此先感謝。

這裏是我的代碼

後端

jQuery(".modify").click(function() { 
         event.preventDefault(); 
         var submit = confirm('Are you sure?'); 
         <?php 
          $post_ids = array(); 
          while($author_entry_posts->have_posts()) : $author_entry_posts->the_post(); 

         array_push($post_ids, get_the_ID()); 

         endwhile; 
         ?> 

         if (submit == true) { 
          var data = { 
           'action': 'modalcall', 
           'postid': <?php echo json_encode($post_ids)?>, 
           'userid': <?php echo get_current_user_id() ?> 
          }; 
          jQuery.post(ajaxurl, data, function(response) { 
           jQuery(response).appendTo('body').modal(); 

            //Script which handles the submit button on the modal pop-up 
           jQuery(".modal_submit").click(function() { 
            console.log("test"); 
            jQuery().submit();  
           }); 
          }); 

         } else { 
          return false; 
         } 
        }); 

前端

<input type="submit" name="submit" value="Submit" class="button modal_submit"> 

回答

1

在你的處理程序點擊模式提交你是不是定義需要提交的表單。

jQuery(".modal_submit").click(function() { 
    console.log("test"); 
    jQuery().submit(); // you are not defining which form to submit. 
}); 

取而代之的是<input type="submit" name="submit" value="Submit" class="button modal_submit">需求是一個需要通過調用jQuery的上提交提交一個表單中。

jQuery(".modal_submit").click(function() { 
    console.log("test"); 
    $(this).closest('form').submit(); // asking to submit the form which contains this button 
}); 
+0

我應該意識到這一點。非常感謝您的幫助。 –