I want to fetch the list of transactions through jQuery/AJAX so it will update on any page I have that list on, when I update the content of this file I want to use. But I don't want to have the SQL queries in the file that I get through jQuery/AJAX since I use different queries for different pages on my website.
- The file transactions.php contains all the SQL queries that I need. In that file, I also have this line:
<div id="transactions"></div>
. - The file fetch-transactions.php contains this list I want to show on the page. In it I have 2 globals (you know,
global $thevariable
) for 2 required variables ($count_transactions
(to count the transactions) and$get_transactions
(to loop the transactions into the list)) that can be found in transactions.php. - The javascripts.js contains all the needed JavaScript codes I have for my website, including this line:
$.get(folder_name + 'ajax/fetch-transactions.php', function(s) { $('div#transactions').html(s); });
As you maybe already have figure out, s contains the content of fetch-transactions.php.
The thing is that none of the variables I have set globally in fetch-transactions.php have any data in them. The are empty! Why is that? Is it because they are not globally set? I don't want to use define
as a variable. I don't think that is even possible for fetching data from the database :P
How can I fix this problem?