Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am passing an array from javascript to PHP using ajax. This is the code I have so far.

  <?php

$i = 1;

while (++$i <= $_SESSION['totalcolumns']) {
    $range = $_SESSION["min-column-$i"] . ',' . $_SESSION["max-column-$i"];?>
        <br><?php echo "Keyword" ?>
        <?php echo $i -1 ?>
        <br><input type="text" data-slider="true" data-slider-range="<?php echo $range ?>" data-slider-step="1">
        <?php } ?>

        <button type="button" >Update</button>
<head>
<script>
var parms = [];
$("[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));
});
$(".output")

    .each(function () {
    parms.push($(this).text());
});

function loadXMLDoc(parms) {
    $.ajax({
        type: "POST",
        url: "update.php",
        data: {
            value: $(parms).serializeArray()
        },
        success: function (data) {
            alert(data);
        }
    });

}
$("button").on('click', function () {
    loadXMLDoc(parms);
});

    alert(parms);
</script>
</head>

On click of button, I am trying to call the PHP script to edit the display of my web page. However, the ajax call to the below PHP statement alerts only the "Am I printed" line.

<?php

    $uid = $_POST['value'];
    echo "Am I printed";
    echo $uid;

    // Do whatever you want with the $uid
?>

Why is the $uid value not returned to my javascript? Is there something am doing wrong?

share|improve this question
 
To debug your code use GET and then open the PHP file directly in a browser with some appropriate value. –  Sébastien Oct 13 at 22:35
 
Hi, I tried the changes you had suggested. I still do not get the values of my array. [link](omega.uta.edu/~rxv1100/slider.php) is the link to my work. –  ram esh Oct 13 at 22:38
 
You will have to encode your array before POSTing.. check out JSON.stringify() –  WindsorAndy Oct 13 at 23:01
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.