Do you need to use a specific libarary Ajax?
The Ajax.Net Control has a Cascading Dropdown pre-created for this function.
MVC, Ajax Control Toolkit . jQuery, , , Ajax , MS MVC.
RESTful ( , ), json- jQuery :
:
<select id="opt1">
<option value='1'>Option 1</option>
<option value='2'>Option 2</option>
</select>
<select id="opt2" disabled></select>
, "id" json, , :
[
{ name: 'option1', value: '1'},
{ name: 'option2', value: '2'}
]
javascript :
$(function() {
$('select#opt1').change(function(){
$.getJSON('/data/myservice',{id: this.value},
function(response) {
var options = '';
for (var i = 0; i < response.length; i++) {
options += "<option value='" + response[i].value + "'>"
+ response[i].name + "</option>";
}
$('select#opt2').removeAttr('disabled').html(options);
});
});
});
, ; jQuery , :
$(function(){})
$(document).ready(function(){})
, , .
$('select#opt1').change(function(){})
<select>
'opt1' , .
$.getJSON()
Ajax . JSON JSON, $.getJSON . - URL- , - /, , - .