I have a simple promise based $.ajax
post loop. The code works as expected, so I am just curious. (All data is shown in the console after the done()
function was executed). However Firebug displays data from the PHP script after the output of the done()
method. Why is this? Does Firebug do something while the code continues to run?
jQuery
var promises = [];
for (i = 0; i < tochange.length; i++) {
var promise = $.ajax({
type:"POST",
url:"updateLevel.php",
data: { graph_plot: tochange[i], new_plot:changeto[i]}
}).done(function(data){
console.log(data);
});
promises.push(promise);
}
$.when.apply(null, promises).done(function() {
console.log('All done')
});
PHP
require_once(dirname(__FILE__) . '/../services/FirePHP.class.php');
require_once(dirname(__FILE__) . '/../services/fb.php');
ob_start();
$firephp = FirePHP::getInstance(true);
$graph_plot = $_POST['graph_plot'];
$new_plot = $_POST['new_plot'];
if ($graph_plot && $new_plot) {
fb("$graph_plot, $new_plot");
}