2012-11-12 16:44
浏览 90


I have 2 selects on my HTML, the options are loaded via my database and the user can switch the options between the boxes, like so:

<select id="column1" multiple size="10" name="FromLB" style="width:150px">
        <?php foreach ($result->result() as $row) { ?>
        <option value="<?php echo $row->id ?>"><?php echo $row->title ?></option>
        <?php } ?>


So far so good, the final plan is for the the user to click Submit and to have access to the data on these two selects in PHP (via an array).

After digging around for a bit, it seems like JSON is the way to go.

I import json.js to my project and get to work:

    function sort_cols(){
            var i=0;
            var p=0;
            var column1 = new Array();
            var column2 = new Array();

            $("#column1 option").each(function()

            $("#column2 option").each(function()

            JSON = JSON.stringify(column1);

                url: '<?php echo base_url() . 'js_tests/update_news'; ?>',
                type: 'POST',
                data: JSON,
                success: function(){


So far I'm only passing one array (for the first select column), but I'm getting an error: Uncaught TypeError: Object ["15","14","1"] has no method 'stringify'

I've been following this answer: How exactly do you use json_decode to pass a javascript array to php?

I'm wondering what am I doing wrong here, and how can I pass my second array (column2) as well?

3条回答 默认 最新

相关推荐 更多相似问题