I am passing a variable from javascript to another PHP page via ajax. I am not able to do it. This is the code I have so far.
<script>
function loadXMLDoc()
{
$.ajax({
type: "POST",
url: "update.php",
data: { value : masterdata },
success: function(data)
{
alert("success!");
}
});
}
$("button").on('click',function(){ loadXMLDoc(); });
</script>
The masterdata variable comes from another javascript function in which I have declared the variable globally, as in this below function.
<script>
var masterdata;
$("[data-slider]")
.each(function () {
var range;
var input = $(this);
$("<span>").addClass("output")
.insertAfter(input);
range = input.data("slider-range").split(",");
$("<span>").addClass("range")
.html(range[0])
.insertBefore(input);
$("<span>").addClass("range")
.html(range[1])
.insertAfter(input);
})
.bind("slider:ready slider:changed", function (event, data) {
$(this).nextAll(".output:first")
.html(data.value.toFixed(2));
masterdata = data.value;
});
</script>
In my update.php file, I am trying to access the variable using $_REQUEST. The code is as below.
<?php
$uid = $_REQUEST['value'];
echo "Am I getting printed";
echo $uid;
// Do whatever you want with the $uid
?>
However, if I click on Update button nothing happens. I just get an alert saying Success for my ajax call. Can someone please help me out?