Don
Don

Reputation: 4663

Is there a way to combine two ajax.load calls to the same URL

I have two .load(URL selector) calls to the same URL, but different selectors.

Is there a way to combine them so there is only one call to the URL, like storing the load results into a string, $('<div>'), and then pulling the two parts out later?

Here is what I have now:

  $("#RECENT").load("HoursApp.php?job_id="+jobid+" #RECENT >*");
  $("#TASKS").load("HoursApp.php?job_id="+jobid+" #TASKS >*")

I'd like to do something like:

  var recent = $("#RECENT");
  var tasks = $("#TASKS");
  var div = $("<div>");

  div.load("HoursApp.php?job_id="+jobid+" #MainPanelBottom");

  recent.html(div.find(" #RECENT >*"));
  tasks.html(div.find(" #TASKS >*"));

Upvotes: 0

Views: 86

Answers (1)

jfriend00
jfriend00

Reputation: 707308

You can do a $.get() of the content and then find the #RECENT and #TASKS parts of the content and put each piece in the div of choice.

Something like this:

$.get("HoursApp.php?job_id="+jobid).done(function(data) {
    var raw = $(data);
    $("#RECENT").empty().append(raw.find("#RECENT").children());
    $("#TASKS").empty().append(raw.find("#TASKS").children());
});

Upvotes: 1

Related Questions