George George
George George

Reputation: 187

Jquery simple Ajax Post PHP not working

I have a simple code but is not working. I want to create a more complex function but I just need the basic structure.

HTML

<span class="cleanreport">Delete Record</span>

Javascript:

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

var token = "test";

$.ajax({
data: {"data": token},
type: "post",
url: "clean.php",
success: function (data) {
console.log(data);
$('.test').html(data);
  }
    });
});

PHP clean.php

$data = $_POST['data'];
echo $data;

What I am doing wrong?

Upvotes: 0

Views: 1663

Answers (2)

tsg
tsg

Reputation: 485

This should work for you:

var token = "test";
$.ajax({
    type: 'POST',
    url: "clean.php",
    data: {id: token},
    dataType: "json",
    success: function(response) {
        // some debug could be here
    },
    error: function(a,b,c) {
        // some debug could be here
    }
});

If not, please debug success and error parameters using console.log().

Based on jquery documentation setting type is an alias for method so this could not be a problem in you case for sure.

Upvotes: 1

Bhavin
Bhavin

Reputation: 17

$( ".cleanreport" ).click(function() {
    var token = "test";
    $.post('clean.php",
    {
       data: token
    },
    function (data,status) {
        //console.log(data);
        $('.test').html(data);
    });
});

Upvotes: 0

Related Questions