For the AJAX logging part, don't rely on any code that might run after the error has occurred. You might want to keep it as simple as possible by making the request with a dynamically-inserted script tag with the source set to be your server script with the data as GET parameters. However, be aware that using GETs will limit you in terms of numbers of characters in the src path (~2000 in IE).
However you do it, it is important to keep it simple as you don't want your error-logging code to be prone to errors in exactly the situations where its most likely to run (the edge cases).
You'll want to disable this in your non-production environments or it could mask problems.
You can use the onerror event in JS to get the details of the error. Hoptoad do this for example and log the errors to their console, Their code re-uses lots of nice JS scripts including a printStackTrace function that is great.....
发布评论
评论(3)
是的,使用window.onerror。
对于 AJAX 日志记录部分,不要依赖错误发生后可能运行的任何代码。您可能希望通过使用动态插入的脚本标记发出请求来使其尽可能简单,并将源设置为服务器脚本,并将数据作为 GET 参数。但是,请注意,使用 GET 会限制 src 路径中的字符数(在 IE 中约为 2000 个)。
无论您如何执行,保持简单很重要,因为您不希望错误记录代码在最有可能运行的情况(边缘情况)中容易出错。
您需要在非生产环境中禁用此功能,否则它可能会掩盖问题。
Yes, use window.onerror.
For the AJAX logging part, don't rely on any code that might run after the error has occurred. You might want to keep it as simple as possible by making the request with a dynamically-inserted script tag with the source set to be your server script with the data as GET parameters. However, be aware that using GETs will limit you in terms of numbers of characters in the src path (~2000 in IE).
However you do it, it is important to keep it simple as you don't want your error-logging code to be prone to errors in exactly the situations where its most likely to run (the edge cases).
You'll want to disable this in your non-production environments or it could mask problems.
是的,您可以使用 window.onerror 处理程序。
Yes, you can use the window.onerror handler.
您可以使用JS中的onerror事件来获取错误的详细信息。 Hoptoad 例如执行此操作并将错误记录到他们的控制台,他们的代码重复使用了许多漂亮的 JS 脚本,包括 printStackTrace功能很棒......
您可以在这里看到他们是如何做到的:
http://hoptoadapp.com /javascripts/notifier.js
You can use the onerror event in JS to get the details of the error. Hoptoad do this for example and log the errors to their console, Their code re-uses lots of nice JS scripts including a printStackTrace function that is great.....
You can see how they do it here:
http://hoptoadapp.com/javascripts/notifier.js