I have a dropdown that lists the data fetched from database using PHP and jQuery Ajax.
- First dropdown List fetches data successfully and populates it in the dropdown.
HTML for first dropdownlist :
$(document).ready(function () {
$(function() {
$.ajax({
type: 'POST',
url: 'getGroupzBase.php',
datatype: 'json',
success: function(data) {
// Call this function on success
console.log(data);
var yourArray = JSON.parse(data);
console.log(yourArray);
$.each(yourArray, function (index, yourArray) {
$('#builder_group').append($('<option/>', {
value: yourArray.id,
text : yourArray.name,
}));
});
},
error: function() {
displayDialogBox('Error', err.toString());
}
});
});
And the dropdown tag -
<select id="builder_group"></select>
For the second dropdown menu does not work with the first dropdown. I have to use jQuery Ajax for the second dropdown as well.
HTML for second dropdownlist :<script> $("#builder_group").change(function(){ console.log("Hello 1"); $('#Ivrmapping_groupZCode').find('option').remove().end(); //clear the city ddl var builder = $(this).find("option:selected").text(); alert(builder); //do the ajax call $.ajax({ url:'getGroupzCode.php' type:'GET', data:{city:builder}, dataType:'json', cache:false, success: function(data) { // Call this function on success console.log(data); var yourArray = JSON.parse(data); console.log(yourArray); $.each(yourArray, function (index, yourArray) { ); }); }, error: function() { displayDialogBox('Error', err.toString()); } }); }); }); </script>
And the dropdown tag -
<select name="Ivrmapping[groupZCode]" id="Ivrmapping_groupZCode">..
</select>
Why is the second dropdownlist not working with first. Can we have more than one jQuery Ajax calls in one page.