Saturday, 15 August 2015

jquery - Comparing data from 2 jsonp calls -



jquery - Comparing data from 2 jsonp calls -

i able compare info 2 separate jsonp calls. using $.getjson have tried $.ajax no luck. under impression problem $.getjson phone call beingness preformed asynchronously, , issue. why tried $.ajax async: false, still not work. this.

$.getjson('url1', function(data){ var = data.information }; $.getjson('url2', function(data){ var b = data.information }; if(a === b) { whatever };

is there way accomplish looking for?

jsonp asynchronous nature ( , if wasn't should still utilize asynchronous version; async:false root of evil ). cannot alter that. in order accomplish trying can utilize $.when:

var requests = []; var data1, data2; requests.push( $.getjson( 'url1', function(data) { data1 = data.information; } ) ); requests.push( $.getjson( 'url2', function(data) { data2 = data.information; } ) ); $.when.apply( $, requests ).then( function( ) { if (data1===data2) { // } });

jquery jsonp

No comments:

Post a Comment