将客户端错误记录到服务器 [英] Log client side errors to the server

查看:158
本文介绍了将客户端错误记录到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

记录服务器端的客户端JavaScript错误

我将客户端JavaScript错误记录到服务器?我正在使用jQuery和MVC。

How can I log client side javascript errors to the server? I'm using jQuery and MVC.

推荐答案

由于他们是客户端错误,您必须将它们发送到服务器使用XMLHttpRequest。您可以使用 try ... catch 语句或 window.onerror

Since they're client-side errors, you'll have to send them to the server using XMLHttpRequest. You could use try...catch statements or window.onerror:

window.onerror = function (msg, url, line)
{
    var message = "Error in "+url+" on line "+line+": "+msg;
    $.post("logerror.aspx", { "msg" : message }); 
}

注意 url 可能在8之前的IE版本中非常不准确。

Be aware that line and url can be very inaccurate in IE versions prior to 8.

这篇关于将客户端错误记录到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆