I am new to Ajax. I have here a function that when a button is clicked, you should be redirected to id.php and at the same time pass the value of clicked_id.
Javascript code:
function clicked(clicked_id){
window.alert("clicked");
window.alert(clicked_id);
$.post('id.php',{ID:clicked_id},
function(data){
window.alert("here");
window.location='id.php';
});
}
Inside my id.php,
<?php
$clickedID = $_GET['ID'];
echo 'here at id.php';
echo $clickedID;
?>
Now the problem is that ID in id.php cannot be identified.
Please help me. I already tried both $_POST and $_GET.
I believe that the problem here is in the passing of the variable.
$_GETinstead of$_POST, but you're making the request with$.post.AJAXrequest is meant for backend processing, not opening a page with variables. If you wanted to load a page withGETvariables you could remove thePOST/GETcall and just usewindow.location='id.php&id='+clicked_id;See the Ajax Introduction for more info