Send email when error occurs
Send email when error occurs
rfitzwater
Posts: 57Questions: 5Answers: 1
How would I go about setting up data tables to send me an email when an data tables error/warning occurs (basically whenever data tables alerts you something went wrong)? Ideally, i'd like the email to contain some variables in the message. For example, I'd like to see error/warning message, the URL, and UserAgent info.
Has anyone setup anything like this? I'm guessing the best method would be to use an ajax call to a php to actually send the mail. What I need to know I guess is how to catch and do the processing when one of these warning/error messages occurs.
Thanks,
-Rhon
Has anyone setup anything like this? I'm guessing the best method would be to use an ajax call to a php to actually send the mail. What I need to know I guess is how to catch and do the processing when one of these warning/error messages occurs.
Thanks,
-Rhon
This discussion has been closed.
Replies
[code]
function _fnLog( oSettings, iLevel, sMesg )
{
var settings = {
from: "blah@server.com",
website: document.domain,
}
$.ajax({
type:"GET",
cache:false,
url:"/js/errorhandler.php",
data: $.param({'message':sMesg, userAgent: navigator.userAgent, 'from':settings.from, 'website': settings.website}),
success: function(test){
//alert("Report sent about the javascript error");
}
})
var sAlert = (oSettings===null) ?
[/code]
My error handler.php script looks like this:
[code]
<?php
$to = "towhom@web.com";
$subject = 'A javascript error has been detected on '. $_GET['website'];
$message = 'Error: '. $_GET['message']. '
';
$message .= 'UserAgent: '. $_GET['userAgent']. '
';
$headers = "From: ". $_GET['from'] ."\r\n"; // Or sendmail_username@hostname by default
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
die("message sent")
?>
[/code]
I am curious looking at the data tables code though. Is it possible to disable the warning alerts with an easy setting?
[code]
$.fn.dataTableExt.sErrMode = 'throw';
[/code]
to have DataTables throw an error rather then alert it.
Allan
Allan