javascript - Getting the sum after multiple AJAX request -
i've created fiddle.
i've used .when().done() method values of facebook likes , github followers problem when sum these 2 values i'm getting
[object object],success,[object object][object object],success,[object object]
jquery
$(function () { $.when( $.ajax({ type: "get", datatype: "json", url: "https://api.github.com/users/bloggerever", success: function (data) { var githubfollowercount =data.followers; $(".githubfollowercount").html(githubfollowercount); } }), $.ajax({ type: "get", datatype: "json", url: "http://graph.facebook.com/bloggerever", success: function (data) { var facebookfollowcount = data.likes; $(".facebookfollowercount").html(facebookfollowcount); } })).done(function (githubfollowercount, facebookfollowcount) { var total=facebookfollowcount + githubfollowercount; $('.totalfollowercount').append(total); }); });
you're getting same response object in ajax call, in then()
wrapped in arrays have first access first member in array, property contains likes / followers etc
).done(function (git, fb) { var total = git[0].followers + fb[0].likes; $('.totalfollowercount').append(total); });
Comments
Post a Comment