NullVoxPopuli
NullVoxPopuli

Reputation: 65173

jQuery: I'm trying to send data via AJAX for jQuery.ui.sortable but it doesn't send everything

I'm trying to build an array structured like

[ 
  [num,
    [num, num num]],
  [num,
    [num, num]],
]

but I get [num,num,num,num,num,num,num] =(

code here: http://jsfiddle.net/WRppV/4/

the problem is that I'm trying to send the var 'x' as data in an AJAX update function that jQueryUI uses for sortable. And it needs to be the array structure above. =\

I'm using the http://jqueryui.com/demos/sortable/#connect-lists kind of sorting.

So, normally I would just to $j(list selector).sortable('serialize')

but because I have two lists I tried this $j(selector1,selector2).sortable('serialize') which is what you do for sorting two lists as in the example. But when the ajax request is made, it only sends the updated list. Which would be fine if I had tons of processing power. but I need the list, and which list it belongs to.

Whats really interesting is that my server says the war is getting sent as

 "content"=>"215,207"

but that doesn't even include the section_id I should be getting something similar to

["141", ["203", "206", "204", "205"],
 "142", ["215", "207"]]

(numbers and structure from chrome when I run the script from the link on my webpage)

my sortable js:

$j("<%= @sortable_contents %>").sortable({
    connectWith: '.section-content',
    axis: 'y',
    zIndex: 1003,
    cursor: 'crosshair',
    update: function(){
        d = $j("#sort_sections > li").map(function(index, element){
            return [element.id.replace(/[a-z]+_/,""), [
                $j(element).find("li.content").map(function(subindex, subelement){
                    return subelement.id.replace(/[a-z]+_/,"");
                }).get()]];
        }).get();
        alert(d)
              $j.ajax({
                type: 'post',
                data: {'content': d},//$j("<%= @sortable_contents %>").sortable('serialize'),//
                dataType: 'script',
                complete: function(request){
                  $j('#sort_contents').effect('highlight');
                  },
                url: '/contents/sort_contents'})
              }
});

Upvotes: 0

Views: 248

Answers (1)

Alex Wayne
Alex Wayne

Reputation: 187214

This is nested. Don't listen to alert, try console.log instead.

In chrome, this gets logged out as this: alt text

Upvotes: 1

Related Questions