I am trying to send data with jQuery and Ajax using $.ajax. I simplified the case just to send one thing but it does not work. Can someone help?
HTML:
<a href="#" id="button">clic!</a>
<br>
<div id="content"></div>
JQUERY
$("#button").click(function(e){
e.preventDefault();
$.ajax({
name: "John",
type: 'POST',
url:"3.php",
success:function(result){
$("#content").html(result);
}
});
});
PHP:
<?php
if( $_REQUEST["name"] )
{
$name = $_REQUEST['name'];
echo $name;
}
?>
You should send data like this:
$.ajax({
type: "POST",
url: "3.php",
data: { name: "John" },
success:function(result){
$("#content").html(result);
}
})