I want to send a JavaScript variable Data
into another php file for a php function. I realized we are unable to use PHP Sessions for that. I tried to do it using AJAX (using jQuery), but I am unable to initialize the AJAX request in to a php variable. However AJAX give me a correct Response:(means ajax is working). but when i print the request [print_r($_POST)], it gave me zero result.
Here is the main html , javascript part.
<div id ='postData'>"+ PostDataResponse + "</div> // PostDataResponse is also ajax response, it is working correctly.
<a href='server.php' onclick= saveData()> click_Here_Link </a>
When I click the click_Here_Link link I wont send the data to requestFile.php file as session variable. I developed the ajax post method in client side like this.(It give me a correct response.)
function saveData(){
// $.post('/ server.php', { postingData: name});
var name = document.getElementById("postData").innerHTML.trim();
$.ajax ({
type: 'POST',
url: 'server.php',
dataType: 'text',
data: {postingData: name},
success: function (Response) {
alert(Response);
},
error: function () {
alert('failure...! ');
}
});
}
Here is the server.php code.
<?Php
$boat = $_POST['postingData'];
echo $boat;
print_r($_POST);
?>
when open the server.php file it give me a error.
Undefined index: postingData