Can't echo jquery (with ajax) variable in php
- by Lars Kerff
I'm trying to post a variable through ajax. But it won't echo the variable in php.
This are the variables (these are working, seen in the log):
$("#slider").bind("valuesChanged", function(e, data){console.log("min: " + data.values.min + " max: " + data.values.max);});
The Ajax part:
$("#slider").bind("valuesChanged", function (e, data) {
$.ajax({
type: "POST",
dataType: "text",
url: "../test.php",
data: { minValue: data.values.min, maxValue: data.values.max },
async: false,
success: function(data){
alert('yeah')
},
error: function(xhr) {
alert('fail') // if your PHP script return an erroneous header, you'll land here
}
});
});
</script>
And php echo:
<?php
if ( $_POST ) {
echo $_POST[ 'minValue' ];
}
?>
Now why does it not echo the post? Thanks!