ajax调用php后,怎么把php中处理的值返回到javascript中? 200
1个回答
展开全部
把ajax的返回值传进callback函数。
例子
In a.html
<script src="jquery.com/jquery-2.1.0.min.js" target="_blank">http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script>
var obj = {};
obj.key = "value";
$.post("b.php", obj,
function(data,status) {
alert("data from php is "+data);
});
</script>
In b.php
<?php
if( $_POST and $_POST["key"]) {
echo "hello world";
}
?>
例子
In a.html
<script src="jquery.com/jquery-2.1.0.min.js" target="_blank">http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script>
var obj = {};
obj.key = "value";
$.post("b.php", obj,
function(data,status) {
alert("data from php is "+data);
});
</script>
In b.php
<?php
if( $_POST and $_POST["key"]) {
echo "hello world";
}
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询