日期:2014-05-16 浏览次数:20440 次
$.ajax({
type:"post",
url:"SecondServlet",
data:"&pid=1",
//dataType:"json",
success: function(data){
;
var d=data;
alert(d);
alert(d.mydata[0].usernum);
//$("p").append(d.mydate[1].teamnum);
},
error:function(err){alert("err");}
<script>直接把json写在js中可行能成功,但像之前从servlet拿到的data却不行,拿到的data还是jaon格式的。
$(document).ready(function(){
var user =
{
"username":"andy",
"age":20,
"info": { "tel": "123456", "cellphone": "98765"},
"address":
[
{"city":"beijing","postcode":222333},
{"city":"newyork","postcode":"555666"}
]
}
//alert(user.address[0]);
alert(user.address[0].postcode);
})</script>
$.ajax({
type:"post",
url:"SecondServlet",
data:"&pid=1",
dataType:"json",