0

Afternoon all,

I have the following code which works fine, apart from i need to send the variable itemID to my php script as $_POST['deleteClientID']. Now i know that data: itemID, is wrong but i'm unsure what it should be?

function deleteItem(item){
    if (confirm("Do you wish to delete this item?")) {
        //alert(item);
        var parent = item.closest('.row');
        var itemID = item.data('client-id');
        $.ajax({
            type: 'POST',
            url: 'includes/delete_client.php',
            data: itemID,
            cache: false,
            beforeSend: function() {
                alert(itemID);
                parent.switchClass("", "redBG", 300, "easeInOutQuad");
            },
            success: function() {
                parent.slideUp(500,function() {
                    parent.remove();
                });
            }
        });
    }
    return false;
}
3
  • this should be data: itemID, like this data: "itemID="+itemID,!!! Commented Jan 3, 2014 at 13:09
  • 1
    data : {deleteClientID : itemId}. Then use $_POST['deleteClientID'] in your script Commented Jan 3, 2014 at 13:11
  • Did you read the doc : api.jquery.com/jquery.ajax ? Example at the bottom Commented Jan 3, 2014 at 13:12

3 Answers 3

4

Data needs to be an object, key: value

data: { deleteClientID: itemID }
Sign up to request clarification or add additional context in comments.

Comments

1

It should be:

data: { deleteClientID: itemID }

Comments

0

Try this

function deleteItem(item){
    if (confirm("Do you wish to delete this item?")) {
        //alert(item);
        var parent = item.closest('.row');
        var itemID = item.data('client-id');
        $.ajax({
            type: 'POST',
            url: 'includes/delete_client.php',
            data: {deleteClientID:itemID},
            cache: false,
            beforeSend: function() {
                alert(itemID);
                parent.switchClass("", "redBG", 300, "easeInOutQuad");
            },
            success: function() {
                parent.slideUp(500,function() {
                    parent.remove();
                });
            }
        });
    }
    return false;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.