Hello everyone, I have a problem with AJAX, and PHP variables ...
I am using a script (script.php) which contains database writing. In the page where I am calling this script, I set the variables so that the script understands which page I am calling it from. For example, in index, I set $PAGE = "INDEX"; or in contat, $PAGE = "CONTACT".
This allows script.php to know where to write to the database. (The $PAGE variable is equal to the column name)
Apparently the AJAX call doesn't know any of the variables I set in the index. This looks like a separate request to script.php, however, how do you get AJAX to have access to these variables?
This would prevent me from doing one script per page ... Understand that having index_script, contact_script, about_script, etc ... That quickly becomes embarassing in my folder ..
There my index code. (I call it twice (include and ajax refresh) because i have two actions in script.php, on refresh, and on load)
<?php
$PAGE = "INDEX"; // MY VARIABLE (ONE FOR THE EXEMPLE, BUT REALLY 7 OR 8)
include('script.php'); // INCLUDE FIRST, DO THE FIRST ACTION
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript">
function refreshh() {
$.ajax({
url: "script.php",
ifModified:true,
success: function(content){
$('#notif').html(content); // <div> to refresh
}
});
setTimeout(notif, 1000); // (1 min = 60000)
}
refreshh();
</script>
<div id="notif"></div>
If anyone have a solution for let ajax access to my variables 🙂 thank you