开发者

ajax and adding the the serializearray in jquery

开发者 https://www.devze.com 2023-03-30 01:04 出处:网络
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?

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');
  开发者_Python百科          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);
            })  
        })


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

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

(no {} around param).


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, 
0

精彩评论

暂无评论...
验证码 换一张
取 消