I've got two pages:
1.php and 2.php
I'm trying to get a PHP variable from 2.php to 1.php through an AJAX request.
This is the script in 1.php
<script>
jQuery('#refresh').click(function(e){
e.preventDefault();
jQuery.ajax({
type:'POST',
url: '2.php',
data: { variable: '<?php echo $PHPvariable ?>' },
dataType : 'json',
success:function(response){
alert(variable);
}
})
});
</script>
For your better understanding, this script is called from within the 1.php file. As you can see I'm trying to retreive the $PHPvariable variable declared in 2.php. Am I doing it correctly??
This is the varialbe delcaration in 2.php
$PHPvariable = 'bla1bla2bla';
$variable = array('PHPvariable ' => $PHPvariable );
echo json_encode($variable);
What is wrong ??