如何从另一个PHP文件使用jQuery获取PHP变量值? [英] How to get a PHP variable value from another PHP file using jquery?
问题描述
我想知道如何从另一个使用jquery的PHP文件获取PHP变量值。事实上,我必须提供文件:test.html和moslem.php。
test.html文件的代码如下:
< html>
< head>
< / head>
< body>
< script src =// ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.jstype =text / javascript>< / script>
< script type =text / javascript>
setTimeout(test(),1000);
函数test(){
$ .ajax({
url:'moslem.php',
类型:'POST',
data:,
成功:函数(数据){
document.write(data);
}
});
setTimeout(test(),1000);
}
< / script>
< / body>
< / html>
以下是moslem.php文件的代码:
<?php
$ chaine =hello!;
?>
我想知道如何使用上面的jquery代码获取变量$ chaine的值,那么我应该怎么做:
data:,
的那个jquery代码。
预先感谢。
请试试这个
< script type =text / JavaScript的>
函数test(){
$ .ajax({
url:'moslem.php',
type:'POST',
success:function(data) {
document.write(data);
}
});
$(document).ready(function(){
setTimeout(test,1000);
});
< / script>
不需要将数据参数传递给ajax。
和php文件将保持与之前发布一样。
<?php
$ chaine =你好!;
echo $ chaine;
?>
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.
Please try with this
<script type="text/javascript">
function test() {
$.ajax({
url: 'moslem.php',
type: 'POST',
success: function(data) {
document.write(data);
}
});
}
$(document).ready(function() {
setTimeout( test, 1000);
});
</script>
No Need to pass the data parameter into ajax. And php file will remain same as before post.
<?php
$chaine = "hello!";
echo $chaine;
?>
这篇关于如何从另一个PHP文件使用jQuery获取PHP变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!