Showing posts with label jquery. Show all posts
Showing posts with label jquery. Show all posts

Tuesday, April 14, 2015

ajax 读取json数据





click to gain json data
 
 
 
 
 
 [
{"optionKey":"1", "optionValue":"Canon in D"},
{"optionKey":"2", "optionValue":"Wind Song"},
{"optionKey":"3", "optionValue":"Wings"}
]

Tuesday, April 7, 2015

jquery 解析 json数据

<script type="text/javascript">
$(document).ready(function(){
$("#button").click(function(){
alert ("good");

$.getJSON("http://localhost/index.php/users", function(json){
         
$.each(json, function(idx, obj) {
             
                 
                    alert(obj.name);
           
             });


       });
});
});
</script>
json格式:
[{"user_id":"2","username":"guest2","name":"John","profile_pic":""},{"user_id":"1","username":"guest","name":"tom","profile_pic":""}]
json的格式对于解析非常重要,一定要规范化