为什么得不到jQuery.post的json返回值?
1.html<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><scriptsrc="js...
1.html
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<script src="js/jquery.hint.js" type="text/javascript"></script>
<script>
jQuery.post("testdate.asp", {stockId: "1"},function(data){
alert(data[0].stockId);
},"json");
</script>
2.asp
<script>
var data=[{"stockId":"1","x":"22.2158","y":"114.2049","district":"123","de_id":"1","olType":"1","name":"xxx","size":"2","price":"3","rent":"4","path":"5","sole":"6","mov360":"6","stockIDDecr":"6","devId":"1","count":"1","keywords":"12","strId":"1"}];
</script> 展开
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<script src="js/jquery.hint.js" type="text/javascript"></script>
<script>
jQuery.post("testdate.asp", {stockId: "1"},function(data){
alert(data[0].stockId);
},"json");
</script>
2.asp
<script>
var data=[{"stockId":"1","x":"22.2158","y":"114.2049","district":"123","de_id":"1","olType":"1","name":"xxx","size":"2","price":"3","rent":"4","path":"5","sole":"6","mov360":"6","stockIDDecr":"6","devId":"1","count":"1","keywords":"12","strId":"1"}];
</script> 展开
展开全部
格式错误:
1、不需要<script>
2、不是json格式
正确的应该是这样:{"stockId":"1","x":"22.2158","y":"114.2049","district":"123","de_id":"1","olType":"1","name":"xxx","size":"2","price":"3","rent":"4","path":"5","sole":"6","mov360":"6","stockIDDecr":"6","devId":"1","count":"1","keywords":"12","strId":"1"}
你那个ASP单独测试运行显示上面我写的这个就可以正确获取了。否则都不行。[ ] 这个是什么?这个是数组哦。正确的JSON格式是{"a":"1","b":"2","c":"3"}
最后面的; 这个也不需要。
题外话:
如果想做成新闻列表的可以这样:
{'MSG':'success','LIST':[{'title':'title1','content':'content1','key':'key1'},{'title':'title2','content':'content2','key':'key2'},{'title':'title3','content':'content3','key':'key3'}]}
1、不需要<script>
2、不是json格式
正确的应该是这样:{"stockId":"1","x":"22.2158","y":"114.2049","district":"123","de_id":"1","olType":"1","name":"xxx","size":"2","price":"3","rent":"4","path":"5","sole":"6","mov360":"6","stockIDDecr":"6","devId":"1","count":"1","keywords":"12","strId":"1"}
你那个ASP单独测试运行显示上面我写的这个就可以正确获取了。否则都不行。[ ] 这个是什么?这个是数组哦。正确的JSON格式是{"a":"1","b":"2","c":"3"}
最后面的; 这个也不需要。
题外话:
如果想做成新闻列表的可以这样:
{'MSG':'success','LIST':[{'title':'title1','content':'content1','key':'key1'},{'title':'title2','content':'content2','key':'key2'},{'title':'title3','content':'content3','key':'key3'}]}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
返回的值直接返回 json 就可以了
[{"stockId":"1","x":"22.2158","y":"114.2049","district":"123","de_id":"1","olType":"1","name":"xxx","size":"2","price":"3","rent":"4","path":"5","sole":"6","mov360":"6","stockIDDecr":"6","devId":"1","count":"1","keywords":"12","strId":"1"}]
这样就可以了,加上其他的东西,全是画蛇添足....jquery为我们实现ajax操作提供了很大的便利,但是应该先了解ajax的基本原理...xmlhttp对象异步访问,只会获取目标输出的文本或者xml,jquery提供了很好的对访问结果的封装,其实就是在函数内部把远程输出的文本转换成json对象...你这里输出的<script>和其他不相干的东西,在xmlhttp对象看来,全是文本
[{"stockId":"1","x":"22.2158","y":"114.2049","district":"123","de_id":"1","olType":"1","name":"xxx","size":"2","price":"3","rent":"4","path":"5","sole":"6","mov360":"6","stockIDDecr":"6","devId":"1","count":"1","keywords":"12","strId":"1"}]
这样就可以了,加上其他的东西,全是画蛇添足....jquery为我们实现ajax操作提供了很大的便利,但是应该先了解ajax的基本原理...xmlhttp对象异步访问,只会获取目标输出的文本或者xml,jquery提供了很好的对访问结果的封装,其实就是在函数内部把远程输出的文本转换成json对象...你这里输出的<script>和其他不相干的东西,在xmlhttp对象看来,全是文本
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询