Help me combine multiple XHRs into one!
Hello,
Currently I am using the following code in order to update two separate divs on my page. However I would like to combine them so when the first call executes, the PHP page will return the result for both portions and then the javascript can parse and update the two divs. Is this possible?
- $("div#mainconsole").append("<div class=\"cmd\">>> " + input.value + "</div>");
var inputval = input.value;
input.value = "";
$.ajax({
type: "POST",
url: "actions.php",
data: "action=cmd&cmd=" + inputval + "<?php print "&sid=$sid\","; ?>
success: function(msg){
$("div#mainconsole").append(msg);
var objDiv = document.getElementById('mainconsole');
objDiv.scrollTop = objDiv.scrollHeight;
$.ajax({
type: "POST",
url: "actions.php",
data: <?php print "\"action=statusbar&sid=$sid\","; ?>
success: function(msg){
$("div#status").html(msg);
}
});
}
});
The actions.php will return something looking like this (not including my comments):
// For appending to first box
<div class="console"><div class="blue">First message here</div><div class="red">Second message</div>
// For setting to second box
<div class="status">Status stuff goes here</div>
So basically I can easily select by class of div to separate them, but I just don't know how.
Thanks much!
M