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 trying to send an array from javascript to PHP script 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>
<script>
    $("[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() {
        var parms = [];
        parms.push($(this).text());
        });


</script>

<script>
function loadXMLDoc()
        {
        $.ajax({
                    type: "POST",
                    url: "update.php",
                    data: { value : $(parms).serializeArray() },
                    success: function(data)
                    {
                        console.log (data);
                    }
                }); 

}
$("button").on('click',function(){ loadXMLDoc(); });
</script>

In my $.output function, I am using the parms [] array to store all the UI slider values which I am trying to pass on to the next PHP script page on a button click event as defined in loadXMLDoc() function. In my PHP page, I am accessing them as below.

<?php

    $uid = $_POST['value'];
    echo "Am I getting printed";
    echo $uid;
    // Do whatever you want with the $uid
?>

However, I am not able to view the data in my update.php script. Can someone please let me know what am doing wrong?

This is the link to my work so far.

share|improve this question
 
data: "value"+parms, IN php $uid = $_POST['value']; ? –  samitha Oct 13 '13 at 14:24
 
ReferenceError: parms is not defined [Break On This Error] data: { value : parms }, ??? –  samitha Oct 13 '13 at 14:25
 
I am defining the parms [] in $output function and trying to use it in the $loadXMLDoc function. Basically, I am trying to send the slider values on button click. –  ram esh Oct 13 '13 at 14:27
 
define this global var parms [] ; –  samitha Oct 13 '13 at 14:28
 
under the $i = 1; –  samitha Oct 13 '13 at 14:28
show 4 more comments

2 Answers

serializeArray returns the json object ,maybe you could try json_decode in your php script,simply like:

$uid_arr = json_decode($uid,true);
print_r($uid_arr);
share|improve this answer
 
Thanks for commenting out. I tried it out but it's not working. –  ram esh Oct 13 '13 at 14:23
 
"Not working" is not a useful comment. What did the print_r show? No data? Wrong Data? –  mplungjan Oct 14 '13 at 4:39
add comment

Just Use

data:  $(parms).serializeArray() 
share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.