Jquery Ajax => Undefined Index Php
i have problem with php. AJAX $(document).ready(function(){ $.ajax({ type: 'POST', // i test post, get... url:'TESTING.php', data: {name: 'alfred'}, success: function
Solution 1:
Along with what the comments say about $_GET not grabbing $_POST data you sent, you are not using the return data.
success: function(data){ //response param
alert(data);
}
Solution 2:
var weightd = $("#weight").val();
var user_id = <?php echo $current_user->ID; ?>;
$.ajax({
type: "POST",
url:"<?php bloginfo('template_directory')?>/ajax/index.php",
data: { weight:weightd,user_ids:user_id},
success:function(result){
$("#result1").html(result);
setInterval(function() {
$('#result1').hide('slow');
}, 5000);
}});
<div id="result1"></div>
try to user like this
Solution 3:
You are sending the data via
POST
, notGET
.Change
$name = $_GET['name'];
To
$name = $_POST['name'];
Your callback function must have argument,
Change
success: function(){ alert("success"); }
To
success: function(data){ alert("success"); // or whatever you wanna do }
Solution 4:
Here is all code
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="//code.jquery.com/jquery.js"></script>
</head>
<body>
</body>
<script>
$(document).ready(function(){
$.ajax({
type: "POST",
url:'TESTING.php',
data: {name: "Alfred"},
success: function(data){ //response param
alert(data);
}
});
});
</script>
<?php
echo "Hi ";
//var_dump($_POST);
$nick = $_POST['name'];
echo $nick;
?>
</body>
</html>
Post a Comment for "Jquery Ajax => Undefined Index Php"