29
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptのエラーログをDBに保存

Posted at

「なんか動かないんだけど?」って言われたとき用に。

window.onerror = function( errorMsg, url, lineNumber ) {
    $.ajax({ 
		url:"js_error_log.php",
		data:{errorMsg:errorMsg, url:url, lineNumber:lineNumber},
		type:"post" 
	});        	
};

・受け取り側のjs_error_log.phpは、POSTされた値をDBに書き込んでるだけ。
・トークンを発行するなど、CSRF対策はした方がいいかも。
・DBに書き込む際に、日時とユーザーエージェントも取得しておく。

29
29
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?