Beware when posting data from a multiple select through ajax. You can’t send an array with a Prototype ajax call.

expl.

function postmydata(){
new Ajax.Request(‘data.php’,
{
method:’post’,
parameters: {selectdata: $F(‘myselect’)},
onSuccess: function(transport){
var response = transport.responseText || alert(“couldn’t add data”);
$(‘mydiv’).update(response);
},
onFailure: function(){ $(‘mydiv’).update(‘error’); }
});
}

This won’t work. Your php page will not get an array.

Solution

replace the parameter part with:
parameters: {selectdata: $F(‘myselect’).join(“,”)}, // this will send a comma seperated string
In your php code use:
$myselect = = explode(‘,’,$_POST[‘selectdata’]);

Related Blogs

Leave a Reply

Your email address will not be published. Required fields are marked *