`
tanglong8848
  • 浏览: 67085 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

jQuery Ajax 实例演示-获取json数据

 
阅读更多
<html>

<head>
<title>jQuery Ajax 实例演示</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<script src="http://code.jquery.com/jquery-1.4.3.js"></script>
<script type="text/javascript">

//方式一
//$.getJSON("http://audicms.ogilvy.com.cn/webapp/front/dealerapi!getdealerlist.action",function(data){alert(data);});

//方式二
//$.get("http://audicms.ogilvy.com.cn/webapp/front/dealerapi!getdealerlist.action","",function(data){alert(data);}); 
//$.each(dataObj.dealers, function(i, v){$("#success").append(v.name).append("<br/>");document.getElementById("result").innerHTML+=v.name+"<br/>";})});

//方式三
$.ajax({
   type: "POST",//请求方式
   url: "http://audicms.ogilvy.com.cn/webapp/front/dealerapi!getdealerlist.action",//地址,就是action请求路径
   data: "json",//数据类型text xml json  script  jsonp
   success: function(msg){//返回的参数就是 action里面所有的有get和set方法的参数
      //$.each(msg.items, function(i,item){});
     var dataObj=eval("("+msg+")"); 
      alert(dataObj.dealers.length);

	 document.getElementById("result").innerHTML=msg;
   }
}); 

</script>

<body>

<div id="result" style="background:orange;border:1px solid red;width:300px;height:200px;"></div>
<form id="formtest" action="" method="post">
<span id="result"></span>
</form>



</body>
</html>


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics