【问题标题】:How do you step through $http response code blocks in the browser?如何在浏览器中单步执行 $http 响应代码块?
【发布时间】:2013-07-03 17:41:42
【问题描述】:

我正在尝试通过一些代码来找出我的应用程序中的奇怪行为。

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

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

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

在这个例子中,我永远无法通过一件事或二件事。

是否有任何调试技巧或工具可用于实际执行 ajax 调用、等待实际响应并逐步执行相应的代码块?

【问题讨论】:

    标签: ajax google-chrome firefox angularjs


    【解决方案1】:

    试试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;
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-04
      • 2023-03-20
      相关资源
      最近更新 更多