我有一张图片:
<img src="imagini/floo.gif" onclick="score()">
我希望“点击”打开文件“c.txt”。 该文件的内容是: 0
我希望每次点击都可以在c.txt中添加100。
我想要这样的事情:
<img src="imagini/floo.gif" onclick="score()">
<script> function score(){ (..do file add.php ...) }</script>
并添加.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);
?>
要放置什么:“(.do file add.php ...)”以使代码生效?
答案 0 :(得分:1)
您需要发送AJAX请求来处理该文件。这是代码的jQuery版本:
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);
});
}