jquery - Combine multiple JSON values as one variable -


currently i'm working on assignment wanted me value 2 json results. here stuck:

1) have 2 json urls both return different values:

    function aa(){         $.getjson("url1.js", function(valuea){         valuea.json;         });     }     function bb(){         $.getjson("url2.js", function (valueb){         valueb.json;         });     } 

2) then, need combine both results , math in jquery:

function math() {  result = valueb.json / valuea.json; alert(result); } 

i can parse both json results failed combine in math function. should in order make work?

thanks :|

the ajax calls, name state, asynchronous. first need "synchronize" them perform math, ie have wait both of them have loaded before math.

to so, put in callback function call checker function check if 2 ajax calls ended, , if perform math.

here's how it:

var valuea, valueb;  function checkifeverythinisfine() {     if ( (valuea || valuea === 0) && (valueb || valueb === 0) )         math(); }  function aa(){     $.getjson("url1.js", function(valuea){         valuea = valuea.json;         checkifeverythinisfine()     }); } function bb(){     $.getjson("url2.js", function (valueb){         valueb =valueb.json;         checkifeverythinisfine()     }); } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -