Clay Smith
Clay Smith

Reputation: 189

ajax and adding the the serializearray in jquery

How do I make this work? I'm trying to do AJAX post. i'm use to doing .serialize but i want to add two more values and keys to the array. how can I do this easily?

        $('#moreprojects').click(function(){
            var skip = $(this).attr('name');
            var more = $(this).attr('rel');
            var param = $('#companies').serializeArray();
            param.push({name: 'skip', value: skip})
            param.push({name: 'more', value: more})
            $.post('projectsmore.php', {param}, function(response){
                $('#projects tbody').append(response);
            })  
        })

Upvotes: 0

Views: 564

Answers (2)

Andrew Sauder
Andrew Sauder

Reputation: 74

You're experiencing problems because of the way that you're injecting the param variable into the $.post. Because the variable param is already an object you don't need to wrap it with brackets.

So instead of:

$.post('projectsmore.php', {param},

it should be:

$.post('projectsmore.php', param, 

Upvotes: 0

Felix Kling
Felix Kling

Reputation: 817238

The way you add the values should be fine. But your call to $.post should be:

$.post('projectsmore.php', param, function(...

(no {} around param).

Upvotes: 1

Related Questions