Working from previous question: Create log text file using Javascript I'd like to log click events from a news scroller. The event detection works and triggers the alert.
$("a.marq").click(function(){
var url = $(this).attr('href');
$.ajax({
type:'POST',
data:"ClickedButton="+url,
url: 'logger.php',
success: function(data){
//alert('req: '+url);
}
}); // END Ajax
});
Taking the php code from the referenced question, I created the logger:
<?php
// File: logger.php
$myFile = "clicklog.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $_POST['ClickedButton'];
fwrite($fh, $stringData);
fclose($fh);
?>
The click events trigger the alert and display the correct data, but nothing is logged by the server. I checked server logs and nothing seemed to trapped. The server is running Apache mod_security, nothing in the logs that I could spot. It's simple "crawl-before-you-run" code, but I was tired of crawling and posted the question. I put the logger.php in the url root, touched the clicklog.txt file.
data: {'ClickedButton': url}and secondly check on your browsers console for errors, if its clean check for post data. And try to adderror: function(jqXHR jqXHR, String textStatus, String errorThrown) {//handle error here}