Send Array Object to jQuery Get

I’m trying to send my array object through ajax using the jQuery .get method, but when it sends, ids show up as multiple parameters and I’m not sure if that’s the way to do it.

Here is my code:



var val = [];
$(':checkbox:checked').each(function(i){
     val[i] = $(this).attr('id').substring(6);
});
		
$.get("/assets/ajax/pm_change_status.php", { s: sess_id(), 'ids[]': val } );


A standard way to send form data is to use serialize.

$.get("/assets/ajax/pm_change_status.php", $('#myform'.serialize());

Thanks paul, but can’t I just use this?

$.get(“/assets/ajax/pm_delete_messages.php”, { s: sess_id(), ids: JSON.stringify(val) } );

It seems to be working. Is this not best practice?

It’s better to use the form to maintain the data, but what you’re doing seems to be working.

I’m not actually submitting a form though. All I am doing is sending the ID to ajax to do the form like manipulation. One of the reasons I am doing this is so that I can have my buttons styled consistent across my site. Style links and buttons the same leads to a lot of styling conflicts which is why I’m making everything links and not using forms.