So this is probably a fairly common problem, but I don't know how to solve it. I have 3 PHP
pages. We'll call them A, B, and C. Page C is included in page B and inflates a div with a table.
I need to click a cell in my table on page A and grab 1 piece of data, store it in a variable, then send it to page C with AJAX
but only after page B has loaded.
So this is what I have so far
jQuery
$('.selectTable td:first-child').on("click", function(e) {
var title = $(this).text();
console.log(title);
window.location = 'pageB.php';
$.ajax({
url:'core/functions/pageC.php',
type: 'post',
data: {'title' : title}
}).fail (function() {
alert('error');
}).always(function(data) {
accountId = $.trim(data);
});
});
Then this is how I call "page C" from "page B"
<div class="myDiv">
<?php include 'core/functions/pageC.php'; ?>
</div>
Then inside pageC
if(isset($_POST['title'])) {
...inflate table, do stuff etc.
} else {
echo 'could not load table';
}
So after I click any "td:first" table cell my alert dialog pops up and says "error" then page B loads and inside the div it has my message 'could not load table'. I console logged the variable, and it is being passed. I think the problem is I'm trying to pass Page C data before Page B has loaded. So when Page B does load it then loads page C again without the post variable being set. Then again I could be dead wrong, just a hunch.
So where am I going wrong? OR Should I be attempting this a different way?
Thanks for your time