Link to home
Start Free TrialLog in
Avatar of chrisvee
chrisvee

asked on

retrieve json response through javascript

I want to retrieve json response through jquery.

$.getJSON("http://json-time.appspot.com/time.json?callback=?", function(data){

    $.each(data, function(key, value){
        document.write(key+": "+value+"<br />"); 
    });
});

Open in new window


code demo

the above code retrieves all data.

But what to do if i want to retrieve only value of  second or hour or minute?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chrisvee
chrisvee

ASKER

not like this  

second: 22
hour: 18
minute: 20

i mean
22:18:20
thank you very much.

 how to log the time exactly when request sent to json and log the time after it arrives.

i want to calculate the time interval between request started and value obtained.
a new question perhaps?
may be. but it is related.
window.a = new Date();
$.getJSON("http://json-time.appspot.com/time.json?callback=?", function(data){
    window.b = new Date();
    $.each(data, function(key, value){
        document.write(key+": "+value+"<br />"); 
    });
    var c = window.b - window.a;
    alert(c);
    //$.post("saveDiff.php", {diff:c}); // send difference to server side
});

Open in new window


hope that help...
at least guide me how to send a parameter along with json url and get its value back.

$.getJSON("http://json-time.appspot.com/time.json?callback=?", function(data){
    document.write(data["hour"]+":"+data["minute"]+":"+data["second"]);
    
});

Open in new window


i want to data parameter along with json url  
http://json-time.appspot.com/time.json?callback=time()

and i want the time var back to me as hour,minute,second.

function time(){
return (new Date()).getTime()
{
$.getJSON("http://json-time.appspot.com/time.json?callback="+time(), function(data){
    document.write(data["hour"]+":"+data["minute"]+":"+data["second"]);
    
});

Open in new window


how to get that time() back to me after passing with json url ?