Passing value JavaScript variable to PHP.
Example
JavaScript
Var ffffd=\'aaaa\'
PHP
<
I have tested the following code and it have worked. So please test this code:
function aa()
{
var ffffd='aaaa';
window.location.href="newpage.php?Result=" +ffffd;
}
click a button then will call aa()
function and will go newpage.php where we get ffffd variable value in Result variable
newpage.php:
extract($_GET);
echo $Result;
One way you can do that is to put it in the cookie:
var ffffd = 'aaaa';
document.cookie = "ffffd="+ffffd; // the ffffd in the "" is the name of the cookie
PHP
$ffffd = $_COOKIE['ffffd'];
if (ffffd == "aaa") { do something... }
In JS:
$.post('ajax.php',{'ffffdd' : ffffdd}, function(data){
});
In PHP
if(isset($_POST['ffffdd'])) $ffffdd = $_POST['ffffdd'];
Javascript is a Client side scripting language that is only executed after the page is fully loaded. PHP on the other hand is an on-demand compiling script. It parses the PHP within the file and outputs the resulting HTML to the user's Browser.