javascript中的多个GET请求

I'm trying to make multiple get requests to 4 different php files within my project but I don't what them to append to the table until all of the requests have come back successful. I've tried inlying all of my requests but I was wondering if there was a faster way to do this besides having to inly the requests?

My current code:

    var content;
    var time_running;
    var next_episode;
    var air_date;
    $.get("functions_tv_name.php?name="+n, function(data){
            content = data;
            $.get("functions.php?name="+n, function(data){
            time_running = data;
                $.get("next_episode.php?name="+n, function(data){
                next_episode = data;    
                    $.get("show_air_time.php?name="+n, function(data){
                     air_date = data;
                     $('#tvResults').append('<tr><td>' + content + '</td><td>' + time_running + '</td><td>' + next_episode + '</td><td>' + air_date + '</td></tr>');
                    });
               });
          });
    });

What you want is to fire all get's immediately. And let each $.get handler do the following:

  1. save its result so that it is accessible to all $.get handlers
  2. check if all $.get have been resolved (successfully or not)

You can do it manually by keeping track of each $.get's status in an object and checking that object as each $.get is getting resolved. E.g. here is a very rough outline

var states = {};
function all_done() {... check states, returns boolean }
// first req
states["req#1"] = {state:"pending", value:null}
$.get("req-1", function(...){
    ...
    states["req#1"].value = "..."
    states["req#1"].state = "resolved"
    if (all_done()) ...
}, error handler....)
// second req -- same thing

HTH