ajax post 不起作用,Ajax post onbeforeunload不起作用

你可以试试这个。 这是我几个月前开发的一个小例子。 在这种情况下,坐标存储在文本文件中,但是您可以用INSERT将其替换到数据库中。

在客户端把这个:

var moves = ""; //Now an String to store the Coords

$(document).ready(function(){

//When you moves the mouse inside the Page then

//concat the Coords into the String var and add a Line-Brak at the end

$("html").mousemove(function(e){

moves += (e.pageX + " x " + e.pageY + "\n");

});

//Here the magic happen: bind a function to onbeforeunload event that POST

//the String to the server

$(window).bind('beforeunload', function() {

$.post("server.php",{name:moves});

});

});

现在,您需要在其中包含

//Capture the String

$cursorMoves = ($_POST['name']);

$myFile = "testFile.txt";

$fh = fopen($myFile, 'w');

fwrite($fh, $cursorMoves);

fclose($fh);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值