علاء محمد
علاء محمد

Reputation: 91

ui sortable multi toArray method never send via $.post

i'm using http://jqueryui.com/sortable/ see this code

var tmp_build_form = new Array();
var groups = $('#form_section').sortable('toArray');
var ordering = '';

if ( groups )
{
    for ( var i in groups )
    {
        if ( typeof(groups[i]) != 'function' )
        {
            ordering += groups[i]+',';

            if ( groups[i].indexOf('group') == 0 )
            {
                var fields = $('#form_section div#'+groups[i]+' div.group_fields_container').sortable('toArray');

                tmp_build_form[groups[i]] = Array();
                tmp_build_form[groups[i]] = fields;
            }
            else
            {
                tmp_build_form[groups[i]] = true;
            }
        }
    }

    tmp_build_form['ordering'] = ordering;
}

i'm trying to send tmp_build_form the via post

$.post(save_url,{'data' : tmp_build_form}, function(data) {
    alert(data);
});  

it send empty array,but when make console.log its give me the array how can i fix this

and this the console results of tmp_build_form http://img41.imageshack.us/img41/1240/30252807.jpg

Upvotes: 1

Views: 192

Answers (2)

Adil Shaikh
Adil Shaikh

Reputation: 44740

Try this...

var myData = $('#form_section').sortable('serialize');


$.post(save_url,{'data' : myData}, function(data) {
    alert(data);
}); 

Upvotes: 1

Jai
Jai

Reputation: 74738

Yeah this will give you a output of array because you have passed an array, so you have to get it this way:

$.post(save_url,{'data' : tmp_build_form}, function(data) {
    alert(data.data); // <-----here '.data' is the passed on which is in array
});

But i suggest you to use console.log(data.data)

Upvotes: 1

Related Questions