简体   繁体   中英

Receive data 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM