代码如下:
<html>
<head>
</head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#aa').load('profile.php');
});
</script>
<body>
<div id="aa">qq</div>
</body>
</html>
----------------------------------------------------
profile.php
<?php
$em=rand(10,100);
$arr = array(
'email' => $em,
'website' => 'http://www.okajax.com',
);
$json_string = json_encode($arr);
echo $json_string;
?>
我想要获得数据,然后做其他操作用。怎么弄啊?
追答那就不要用load这个方法呀
用ajax请求呀
$.get("profile.php",
function(data){
// data就是profile.php返回的值,但会被jquery包装成json格式,所以data是一个json对象,可直接使用
$("#aa").html(data.website);
},"json");
谢谢。但是我想获得profile.php中的数据。php里面的那个rand我是假设为数据库中的数据.
追答php里数据怎么查询还是跟平常查询一样
返回的数据会给success: function(msg)的msg