I am having index.php which will listens mouse coordinates on moving it. I want to send these coordinates to second file (say second.php). For this I have placed post fields inside mousemoving activity. But i am unable to receive these values in second.php file. Help me with this thing. I am attaching my code below :
<html>
<head>
<script type="text/javascript" src="jquery-latest.js"></script>
<script type="text/javascript">
jQuery(document).ready(function()
{
$(document).mousemove(function(e)
{
$('#status').html(e.pageX);
$('#status1').html(e.pageY);
$.post("second.php",
{
x:10,
y:20
}, function coord(data)
{
$("#div1").load("second.php"); },"html"
}
});
})
</script>
<body>
<h2 id='status'>
</h2>
<h2 id="status1">
</h2>
<div id="div1"></div>
</body>
</html>
and the second file normally receives post values and returns it after addition. Am i going on a wrong track or is there an alternate way for doing this. Help me with it.
I advise you to not do this thing, every time you move the mouse you send a request is very hard to manage think another way to do what you want.
but this code can works for your scope:
<script type="text/javascript">
jQuery(document).ready(function()
{
$(document).mousemove(function(e)
{
$('#status').html(e.pageX);
$('#status1').html(e.pageY);
$.ajax({
type: 'POST',
url: 'second.php',
data: {
'x': '10',
'y': '20'
},
success: function(msg){
//what you want after request
}
});
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With