POST is Empty Array On Ajax Post Method

490 Views Asked by At

Using jquery ajax with Post method I have a code like

var col = senario +"_"+eTraget;
var data='column='+col;

$.ajax({
    type:"POST",
    url:"con/data.php",
    data:data,        
    dataType: 'json',
    success: function (html) {
    coords = html;
    console.log(data);
})

now as you can see I used the console.log(data); and it print the result like column=ce_3000 in the console but in PHP file I have nothing in Array()!

<?php
define ( 'DB_HOST', 'localhost' );
define ( 'DB_USER', 'root' );
define ( 'DB_PASS', 'root' );
define ( 'DB_NAME', 'test' );
$col = $_POST['column'];

$con = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);
$query = "SELECT x, y  FROM  ecoloprojects WHERE". $col."=1";

print_r($_POST);
$con->close();
?>

I tried to printr the POST array but it is empty can you please let me know why this is happening?

Update:

enter image description here

1

There are 1 best solutions below

6
On

Try this in the JS instead:

var col = senario +"_"+eTraget;

$.ajax({
    type:"POST",
    url:"con/data.php",
    data:{column: col},        
    success: function (html) {
        coords = html;
        console.log(data);
    }
});