douyi1855 2015-10-27 23:07
浏览 45

接收数据json / jquery

Good evening!

Trying to learn how to receive data with json/JQuery using following function. I've managed to store the php variable in a json variable (var ar), and it seems to contain what I want (according to console.log, document.write says [object Object]) but I'm not sure how to implement it in the function.

  • 写回答

1条回答 默认 最新

  • duanjing7651 2015-10-28 06:32
    关注

    Depending on the reason for your implementation, but if you are just processing data from a post, it would probably be more efficient to parse the JSON via PHP not with jQuery.

    I have made a simple example about retrieving JSON data and parsing the result data, 1 key at a time. Depending on your JSON schema you may have to parse each key differently as they may have different children nodes.

    var url = "http://beta.json-generator.com/api/json/get/EkRU_ItZl";
    
    $.getJSON( url, function( data ) {
        console.log(data);
        $.each( data, function( key, val ) {
            $('#result').append("Key:" + key + " Value:" + JSON.stringify(val) + "<br/>" );
        });
    });
    

    Here is a basic example in jsFiddle: http://jsfiddle.net/DJRavine/k8cxn4u9/

    I hope this helps out.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题