Search code examples
jquerypostserializearray

Using serializeArray for non-form objects?


I'm trying to post some data built from some non-form elements but I can't seem to crack it.

How can I create an array in the same format as serializeArray() does with form fields?

I've tried several variations on this but it only picks up the last .active tag.

$('li.tag.active').each(function() {
    values = {};
    values['tagID'] = $(this).attr('id');
});

$.post("/scripts/php/process.php",{     
    'data': data,
    funcName : 'tagResults'
},function(results){
    $("#results").html(results);
}) 

Solution

  • ok - found this in the end which works exactly as if it was input fields with serializeArray()...

    function getTags(){
    
            var data = new Array();
    
            $('li.tag.active').each(function() {
                    data.push({ 'name':$(this).attr("name"), 'value':$(this).attr("id")});
             });
    
             $.post("/scripts/php/process.php",{ 
                 'data': data,
                 funcName : 'tagResults'
            }) 
    
    }