I'm trying to send a simple string to the database. In order to see if I'm half way there, I'm checking to see if $_POST has anything set -- but it doesn't.
Here is my simple form, on an index.php:
<form action="" method="POST">
<input type="text" name="add_item" id="add_item">
<input type="button" value="submit" id="button">
</form>
And here is the AJAX from that form, where the success is triggered:
var add_item;
$('#button').click(function(e){
e.preventDefault();
add_item = $('#add_item').val();
console.log(add_item);
$.ajax({
type: 'POST',
url: 'sendData.php',
data: 'send me!',
success: function(data){
alert('lol');
}
});
});
And on the sendData.php, but there is nothing in the $_POST global:
var_dump($_POST); // returns 0
if (isset($_POST['add_item'])):
$add_item = $_POST['add_item'];
$submit = new Connection();
$submit->connect_db();
$submit->add_to_DB($add_item);
endif;
As you can see, I'm trying to send it to the database; but before that I'm trying to see if anything is in the $_POST global -- but it returns 0.
Would anyone know why? I'm new to this and I can't find any concrete tutorials explaining simply.
$_POSTwhen you sendsend me!?