I need to call a php page page1.php with parameters through $_POST method from a jQuery code, without reloading the page from which I make the call, let's call it page0.php ..
So this is the code I wrote in page0.php
<img id="leftUp" src="/imagenes/cursor_1.png" width="52" height="52" ondragstart='return false;'/>
<div id="activity"style="text-align:left;position:relative;left:120px;">
<h3 style="color: yellow;"></h3>
</div>
<script>
var $level = 1;
$("#leftUp").click(function()
{
var $hOffset = -5;
var $vOffset = -5;
$hOffset *= $level;
$vOffset *= $level;
$("#activity").text("Values h: " + $hOffset + " - v: " + $vOffset);
event.preventDefault();
$.ajax(
{
url: "page1.php",
method: 'POST',
data: new FormData(this),
params:
{
interrupt: '14',
hOffset: $hOffset,
vOffset: $vOffset
},
contentType: false,
cache: false,
processData: false,
success: function(data)
{
alert('Success');
},
failure:function(transport)
{
alert('Error');
}
});
});
});
</script>
And the code for page1.php is basically this:
<?php
if(isset($_POST["interrupt"]))
{
$interrupt = urlencode($_POST["interrupt"]);
/*
write the interrupt number into the interrupt
reference file
*/
exec("echo '$interrupt' > $intFile");
}
if(isset($_POST["hOffset"]))
{
$hOffset = urlencode($_POST["hOffset"]);
}
if(isset($_POST["vOffset"]))
{
$vOffset = urlencode($_POST["vOffset"]);
}
/* other stuff here ... */
include("page0.php");
?>
I previously did something similar in the thread: 'Upload a file and reloading a div instead reloading a page', but my code is not working at all.
The content of the div activity is successfully updated, and the pop-up window of 'Success' string is shown, but the PHP code seems to be not executed.
The problem should be into the jQuery code inside the $.ajax block, but I am not an experienced web programmer, so I really do not know how I can solve this.
Any suggestion is very appreciated. Thank you in advance.
EDIT: I modified the ajax as follows:
$.ajax(
{
url: "page1.php",
type: 'GET',
data:
{
interrupt: "14",
hOffset: $hOffset,
vOffset: $vOffset
},
contentType: false,
cache: false,
processData: false,
success: function(data)
{
alert('Success');
},
failure:function(transport)
{
alert('Error');
}
});
But still nothing happens.