0

An initial ajax event saves a unique numerical ID into the value attribute of the following input tag:

 <input class="avatar-id" id="avatar-id" name="id" value="">

I would like to use jquery ajax to send this value to a php script named delete_list.php. I think I am incorrectly using the jquery ajax DATA setting here to pull the value out:

$("#dformclose").click(function() {
if (confirm("Are you sure you want to cancel this? Your image and any information in this form will be deleted")) {
    var id = id;
        $.ajax({
            type: "POST",
            dataType:"html",
            url: "delete_list.php",
            data: "#avatar-id.attr(value.id)",
            success: function(response) {
              location.reload(true);
            }
        });
    }
         else 
      { 
    return false;
 }
});

How can I correctly use this script to process the ID on the php end?

2
  • $("#avatar-id").val() will give you value Commented Jan 7, 2015 at 3:27
  • Its not secure to delete some data over javascript post request Commented Jan 7, 2015 at 3:31

2 Answers 2

1
var idValue = $('#avatar-id').val();

$.ajax({
    type: "POST",
    dataType:"html",
    url: "delete_list.php",
    data: {id: idValue},
    success: function(response) {
      location.reload(true);
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

it appears the whole ajax call isnt running. the file delete_list doesn't show up in my consul log using my Browser dev tool
0

Simply,

jquery

data: $('input#avatar-id').val(),

php

To access in php use $_POST['id']

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.