Prototype: submit multiple select with ajax call

August 11th, 2009 § 0

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

Related posts:

  1. Pdo get column names

Tagged:

§ Leave a Reply

What's this?

You are currently reading Prototype: submit multiple select with ajax call at westworld: a webmasters best friend.

meta