0

I have a image:

 <img src="imagini/floo.gif" onclick="score()">

and i want "on click" to be opened a file "c.txt". That file's content is: 0

And i want on every click, to be added 100 in c.txt.

I want something like this:

 <img src="imagini/floo.gif" onclick="score()">
<script> function score(){ (..do file add.php ...) }</script>

And add.php:

<?php
$c = "c.txt";
$fh = fopen($c, "r");
$current = fread($fh, filesize($c));
fclose($fh);
$current++;
$fh = fopen($c, "w");
fwrite($fh,$current);
fclose($fh);
?>

What to put in place: "(..do file add.php ...)" for the code to work?

  • Try using ajax and jQuery, and posting the data. Them use the on click or (pseudo code) $`('#link').click.action{function` etc. not very strong with jquery to run the function with Ajax inside – 1789040 Mar 16 '13 at 18:27
  • can you tell me all the code, please? –  Mar 16 '13 at 18:28
  • see here http://stackoverflow.com/questions/10214723/jquery-ajax-post-data – 1789040 Mar 16 '13 at 18:29
  • what to take from there? –  Mar 16 '13 at 18:41

1 Answers1

1

You need to send an AJAX request to process the file. Here is a jQuery version of the code:

function score() {
    $.post("add.php", function(data) {
       //This callback executes after the request was successfull
       // echo something back to read from here as `data`
       console.log(data);
    });
}
Starx
  • 77,474
  • 47
  • 185
  • 261
  • it must be like this: ? –  Mar 16 '13 at 18:29