0

我看到了很多关于如何使用 chrome、firebug 等调试 javascript 的问题和答案......

但这都涉及一个预加载的 js 文件。

有没有办法调试(逐步,而不是警报)作为 Rails AJAX 请求响应的 js 脚本?

4

2 回答 2

1

Assuming that you have access to edit the file that Rails returns, you can temporarily insert a debugger; statement.

Then, when you have your browser's debugging console open as you receive the AJAX response, JS execution will halt and you can step through execution in the debugger.

于 2012-12-16T14:37:09.613 回答
1

如果您更改响应以包含debugger关键字,它应该将其作为断点。您只能从成功处理程序本身检查 ajax 调用的结果。所以在这种情况下,响应将是:

var test = "it isn't working";
var response = $.ajax({
    type: 'GET',
    url: 'jquerydemo.php', 
    success: function(data, textStatus, xhr){
            debugger;
            //alert("it's working");   
        },
    error: function(xhr, textStatus, errorThrown){
            debugger;
            //alert("Error detected");
        }
 });

显然不要忘记在它上线时将其删除。:D

于 2012-12-16T14:44:46.167 回答