I would like to know how to get get a PHP variable value from another PHP file using jquery. In fact I have to files: test.html and moslem.php . the code of test.html file is as below:
<html>
<head>
</head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
setTimeout( "test()", 1000);
function test() {
$.ajax({
url: 'moslem.php',
type: 'POST',
data: ,
success: function(data) {
document.write(data);
}
});
setTimeout ( "test()", 1000);
}
</script>
</body>
</html>
And the code of moslem.php file is as below:
<?php
$chaine = "hello!";
?>
I would like to know how can I get the value of the variable $chaine using the jquery code above, then what should I put at the line :
data: ,
of that jquery code.
Thanks in advance.
echo 'hello'is what you need.include otherfile.phpand any variables set in otherfile.php will now be available in the PHP code you called it from.