0

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?

3
  • To debug your code use GET and then open the PHP file directly in a browser with some appropriate value. Commented Oct 13, 2013 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. Commented Oct 13, 2013 at 22:38
  • You will have to encode your array before POSTing.. check out JSON.stringify() Commented Oct 13, 2013 at 23:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.