I'm using jQuery post to post checkbox values to another file, I know the page works and the logic is correct because when I'm not using jQuery post the page works fine, problem is it seems to mess with the array and therefore causes it to not work properly
My radio field uses these form fields:
<input type="checkbox" name="radio[]" value="<? print $id; ?>">
Which when posted to the next page is processed by
if ($_POST['radio']){
foreach($_POST['radio'] as $val) {
This is what posts when I get as a normal form submit, using print_r($_POST);
Array (
[radio] => Array (
[0] => 13
[1] => 12
)
[ros] => sell
[submit] => submit
)
That works fine, problem is it doesn't work in jQuery AJAX, so I can process the data without having to refresh, when I post the form using jQuery AJAX, the data looks like this:
Array (
[ros] => sell
[submit] => submit
[radio] => radio %5B %5D=15&radio%5B%5D=14&ros=sell
)
This is my jQuery AJAX post script:
function submitgarage() {
var submit = $("input[name=submit]").val();
var ros = $("#ros option:selected").val();
var radio = $("#garageform").serialize();
$.post("ajax/vehicles/garage.php", { ros: ros, submit: submit, radio: radio },
function(data) {
$('#results').html(data);
});
}
As you can see it is adding the %5B %5D etc, I have attempted to use utf8_decode, caused a server 500 error, attempted to use urldecode, which I suspected wouldn't work anyway and I was right, I just cant seem to get it to post the same as it did before.
I have checked other topics on Stack Overflow for the same kind of thing and couldn't seem to find a solution.