AJAX call on Multiple selection in Select element
How do you make a jQuery AJAX开发者_运维知识库 call on selection change of a select
input enabled for multi-select.
i use this method, only you can see more in post:
Using jQuery, how do you mimic the form serialization for a select with multiple options selected in a $.ajax call?
var mySelections = [];
$('#mySelect option').each(function(i) {
if (this.selected == true) {
mySelections.push(this.value);
}
});
$.ajax({
type: "post",
url: "http://myServer" ,
dataType: "text",
data: {
'service' : 'myService',
'program' : 'myProgram',
'selected' : mySelections
},
success: function(request) {
result.innerHTML = request ;
}
}); // End ajax method
<form id="Myform">
<select name="myoption" id="MyOptions" multiple="multiple">
<option value="1" selected=""> Value 1 </option>
<option value="2" selected=""> Value 2</option>
<option value="3"> Value 3 </option>
</select>
</form>
var Mydata = $('#Myform').serialize();
OR
var Mydata = $('#MyOptions').serialize();
So it gets from all the selected values
$.ajax({
type: "post",
url: "http://URL" ,
dataType: "text",
data: Mydata,
success: function(request) {
result.innerHTML = request ;
}
});
精彩评论