如何在浏览器中单步执行$ http响应代码块?

时间:2013-07-05 15:05:12

标签: ajax google-chrome firefox angularjs

我正试图通过一些代码来弄清楚我的应用程序中的奇怪行为。

当我进入$ http.post函数调用时,我只能单步执行函数调用,.success函数调用和.error函数调用。

我永远无法等待响应并逐步执行相应的代码块。

$http.post("php/someFunction.php")
  .success(function(data, status)
  {
    ... do thing ONE;
  })
  .error(function(data, status)
  {
    ... do thing TWO;
  });

在这个例子中,我永远不能单步执行ONE或TWO。

我是否可以使用任何调试技巧或工具来实际执行ajax调用,等待实际响应,并逐步执行相应的代码块?

1 个答案:

答案 0 :(得分:0)

尝试debugger声明:

$http.post("php/someFunction.php")
  .success(function(data, status)
  {
    debugger; // debugger will kick in if success
    ... do thing ONE;
  })
  .error(function(data, status)
  {
    debugger; // debugger will kick in if error
    ... do thing TWO;
  });
相关问题