I know this question has been asked in various forms, but I'm very new to ajax and php and I was hoping for some help. I have a JS function that takes a passed variable that I'd like to post to a new page and then go to that page. However I'm not sure how to post to the next page then go to the page and get the data.
For example: my function takes a course name, I'd like to post the name to the new page and then redirect to the new page and assign the data to a textbox. Here's what I've tried:
function clickLogo(val){
console.log(val);
$.ajax({
url: 'newPage.php',
type: 'POST',
data: 'courseTitle=' +val,
success: function (response) {
location.href = "newPage.php";
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
}
/NEW PAGE/
<?php
include ('config.php');
@ob_start();
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$courseTitle = $_POST['courseTitle'];
echo $courseTitle+"!!!";
echo "<script type = 'text/javascript'>document.getElementById('#headerDiv').innerHTML = ".$courseTitle."</script>";
}else{
echo "NO POST!!";
}
?>