2

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");
}
Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132
Grushton94
  • 603
  • 1
  • 7
  • 17
  • Weird indeed. Have you tested in Chrome? – Jeremy Thille Feb 16 '15 at 15:35
  • I know right. I haven't. I do not have firebug installed on chrome, but i will get it and post the result. – Grushton94 Feb 16 '15 at 15:36
  • I have installed firebug light on chrome, but cannot seem to find a way of using the fb() function any ideas? – Grushton94 Feb 16 '15 at 15:45
  • You don't need anything else in Chrome. Just press F12. Tadaaaa – Jeremy Thille Feb 16 '15 at 15:49
  • i have the firebug screen up, but on firefox there is a function to write to the firebug console "fb()". this is not writing to the chrome firebug console. so i can't test if the delay is there – Grushton94 Feb 16 '15 at 15:50
  • No idea what fb() does in Firebug. Uninstall Firebug lite from Chrome, you don't need it. Just press F12 to get Chrome's own debugger, which I personally much prefer to Firebug. Firebug lite is a javascript emulation of Firebug, that may be why it gives you wrong results on promises. – Jeremy Thille Feb 16 '15 at 15:54
  • You are obviously using the [FirePHP](http://firephp.org/) extension for Firebug. You should add that information to you question. Note that the `fb()` function is coming from FirePHP. Also, you should append a screenshot of what you see and write down the console output you expect, so it's easier to understand what you mean. – Sebastian Zartner Feb 17 '15 at 12:43

0 Answers0