Im trying to add data to a preserialised array. Its not working. Anyone spot why?
$("#show-friends").live("click", function() {
var friendSelector = $("#jfmfs-container").data('jfmfs');
var sendArr = $(friendSelector).serializeArray();
sendArr.push({ name: "userid", value: "<?php echo $userId;?>" });
sendArr.push({ name: "fid", value: "<?php echo $fid;?>" });
$.post({
url:'test.php',
data: sendArr,
});
});
Edit: I changed my code to:
$("#show-friends").live("click", function() {
var friendSelector = $("#jfmfs-container").data('jfmfs');
var sendArr = friendSelector.serializeArray();
$.post({
url:'test.php',
data: "name=<?php echo $userId;?>&fid=<?php echo $fid;?>&jsondata="+sendArr,
});
});
However I get a error friendSelector.serializeArray is not a function
Your
$postcall is incorrect. You don’t pass an object like you would for$.ajax. You pass the url, then the data (if any), and then a callback (if you want).It should be:
Or with
$.ajax:EDIT: When you do
$("#jfmfs-container").data('jfmfs'), this is return you the value of thejfmfsdata.friendSelector.serializeArraydoesn’t work, becausefriendSelectoris whatever the data was, not a jQuery object.