Can't echo jquery (with ajax) variable in php
Posted
by
Lars Kerff
on Stack Overflow
See other posts from Stack Overflow
or by Lars Kerff
Published on 2013-07-05T09:40:17Z
Indexed on
2013/11/02
21:55 UTC
Read the original article
Hit count: 217
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!
© Stack Overflow or respective owner