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,
精彩评论