0

So i have this jQuery:

$("#dropbin").droppable(
    {
    accept: '#dragme', 
    hoverClass: "drag-enter",
    drop: function(event) 
    {
      var noteid = "<?=isset($_POST['noteid']) ? $_POST['noteid'] : "" ?>";

      if (confirm('Delete the note?')==true) 
      {
        $('#dragme').hide();
        debugger
        $.ajax({
          type: 'POST',
          data: noteid,
          datatype: 'json',
          url: 'deleteNote.php',
          success: function(result)
              {
                  alert("Success");
              }
        });

        window.location = "http://discovertheplanet.net/general_notes.php";
      }
      else
      {
        window.location = "http://discovertheplanet.net/general_notes.php";
      }
    }
  });

and that includes this url: url: 'deleteNote.php',

in deleteNote.php:

<?php

include "connectionDetails.php";

?>

<?php

if (isset($_POST['noteid'])) 
{
    // $noteid2 = $_POST['noteid1'];

    echo "You finally hit this bit, congratulations...";

    // $stmt = "UPDATE Notes SET Deleted = GETDATE() WHERE NoteID = (?)";
    // $params = $noteid2;

    // $stmt = sqlsrv_query($conn, $stmt, $params);

    // if ($stmt === false) 
    // {
    //  die( print_r(sqlsrv_errors(), true));
    // }

}

else
{
    echo "No Data";
}


?>

Now even in the URL if i run /deleteNote.php?noteid=25 it hits the "No Data" part of my PHP.

When i run in debugger it populates the variable noteid with a NoteID so that bit is working but the PHP file is saying its not set?

7

1 Answer 1

2

Let's look in your Ajax call:

$.ajax({
      type: 'POST',
      data: noteid,
      datatype: 'json',
      url: 'deleteNote.php',
      success: function(result)
          {
              alert("Success");
          }
    });

Looks nice, but you are sending post data with no id, you're just sending a value. Try this instead.

  $.ajax({
      type: 'POST',
      data: {
          noteid: noteid
      },
      datatype: 'json',
      url: 'deleteNote.php',
      success: function(result)
          {
              alert("Success");
          }
    });
Sign up to request clarification or add additional context in comments.

6 Comments

i have made this alteration but its still not working, still hitting the no data part
Your deletenote.php still has if (isset($_POST['noteid']))?
Yes, also i've noticed its not hitting my debugger now though?
Still hitting the alert?
ok not sure what happened there but its hitting the debugger and alert as it was before however still not hitting that php :( i have also uncommented out the PHP in the file so it should now update the item in the database
|

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.