当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Using plain jquery / javascript to create a popup confirm box

问题描述:

Here is the extract code of how to make a confim box when delete,

For HTML part

A link is to trigger JS code , but it will trigger the php code at same time

For JS part

popupbox is triggered

For PHP part

Process the sql query, it should be ok

The problems are...

  1. I should use js to trigger the php page? But how can i let the php page know that which ListID i want to delete?
  2. What should i put in the html link?
  3. What if i want to include the list name in the popup box e.g. do you want to delete list A ,where list A is a variable already. The only thing is how can i append it to the popup box

Thank you

HTML

<a id="delete" href='delete.php?id=$set[ListID]'>Delete</a>

JS

$(function(){

$("#delete").click(function() {

// what should be add here?

});

});

PHP

//connection db

INSERT INTO delete_list SELECT * FROM list WHERE ListID=?;

INSERT INTO delete_user_list SELECT * FROM user_list WHERE ListID=?;

INSERT INTO delete_require_attributes SELECT * FROM require_attributes WHERE ListID='2';

INSERT INTO delete_subscriber SELECT * FROM subscriber WHERE ListID=?;

INSERT INTO delete_subscriber SELECT * FROM subscriber WHERE ListID=?;

DELETE FROM list WHERE ListID = '1'

Sorry, I mess up the previous question as i found that the plugin i used in last question does not work for me.

网友答案:

i had done this by giving the id to the HTML element itself with data (HTML5 ref) sweet to use with jQuery. After this you can do an ajax call optional to delete server-side in the database.

Example

<a data-id="<?php echo $set[ListID]; ?>" class="delete-trigger" href='javascript:;'>Delete</a>

JS

$(function(){
    $("#delete-trigger").click(function() {
        var id = $(this).data('id');
        $.ajax({
            url: 'http://yoururl.com/delete.php?id=' + id,
            success: function(data) {
                console.log('deleted');
            }
        });
    });
});
网友答案:

html

<a class="delete" data-listname="<?php echo $set['ListName']?>" href="delete.php?id=<?php echo $set['ListID']?>">Delete</a>

js

$(function(){
  $(".delete").click(function() {

    return confirm('Are you sure you want to delete ' + $(this).data('listname') + '?');

 });
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: