jQuery $.each not working in ie9
-
19-10-2022 - |
Question
Using the following code to change out select boxes but I get an error on the line of code with $.each in ie9...
var json = (function(){
var json = null;
$.ajax({
'async' : false,
'global' : false,
'url' : 'https://s3-us-west-2.amazonaws.com/mymessmytide/albertsons.json', //https://s3-us-west-2.amazonaws.com/mymessmytide/
'dataType' : 'json',
'success' : function(data) {
json = data;
}
});
return json;
})();
$('select#state').change(function(){
var thestate = $(this).val();
var cities = [];
$.each(json, function(key, value) {
if (cities.indexOf(value.city) == -1 && value.state == thestate) {
cities.push(value.city);
}
});
$('select#city')
.removeAttr('disabled')
.empty()
.append('<option>CHOOSE YOUR CITY</option>');
$('select#store')
.empty()
.attr('disabled', 'disabled')
.append('<option>STORE</option>');
$.each(cities.sort(), function(key, value) {
$('select#city').append('<option value="' + value + '">' + value + '</option>');
});
});
Here's the error I get:
SCRIPT5007: Unable to get value of the property 'length': object is null or undefined
Pas de solution correcte
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow