The smssender.txt file:
0
The script tag in the page:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function handleTextFile()
{
document.getElementById('counter').style.color = "rgb(0, 255, 0)";
document.getElementById('counter').style.fontWeight = 'bold';
var downcounter = 0;
$.get("http://www.gfcf14greendream.com/counters/smssender.txt", function(data){
downcounter = data;
if (downcounter == 1) $("#counter").text("SMS Sender has been downloaded " + downcounter + " time...");
else $("#counter").text("SMS Sender has been downloaded " + downcounter + " times...");
});
$("#downbutton").click( function(){
downcounter++;
if (downcounter == 1) $("#counter").text("SMS Sender has been downloaded " + downcounter + " time...");
else $("#counter").text("SMS Sender has been downloaded " + downcounter + " times...");
$.post("http://www.gfcf14greendream.com/PHP/overwritefile.php", {counter: downcounter, file: "http://www.gfcf14greendream.com/counters/smssender.txt" }, function(data){
});
});
}
</script>
and the overwritefile.php:
<?php $counter = $_POST['counter']; $file = $_POST['file']; file_put_contents($file, $counter); ?>
I know next to nothing about PHP, but I needed this because I would like a counter for my page, without actually having to get a pre-made like the one I have at this other page ( http://www.gfcf14gre...votebuster.html ). The function handleTextFile() is run on the HTML body tag:
<body onload="handleTextFile()">
The 'counter' id is for a DIV that will be set to display the number of times the program is downloaded. This part:
var downcounter = 0;
$.get("http://www.gfcf14greendream.com/counters/smssender.txt", function(data){
downcounter = data;
if (downcounter == 1) $("#counter").text("SMS Sender has been downloaded " + downcounter + " time...");
else $("#counter").text("SMS Sender has been downloaded " + downcounter + " times...");
});
, works just fine and "SMS sender has been downloaded 0 times..." is displayed. The post part is what I'm not getting right:
$("#downbutton").click( function(){
downcounter++;
if (downcounter == 1) $("#counter").text("SMS Sender has been downloaded " + downcounter + " time...");
else $("#counter").text("SMS Sender has been downloaded " + downcounter + " times...");
$.post("http://www.gfcf14greendream.com/PHP/overwritefile.php", {counter: downcounter, file: "http://www.gfcf14greendream.com/counters/smssender.txt" }, function(data){
});
});
The object for the "downbutton" id is a css div button. The variable downcounter is easily incremented and displayed, but if I check the file at http://www.gfcf14gre...s/smssender.txt I still see a 0. Is it that jquery cannot call an external php? Or am I just calling it incorrectly? Please let me know your thoughts, thank you

New Topic/Question
Reply



MultiQuote




|