JQuery IE JSON error

when i run this JS in FF or Safari it works correctly, but in IE I get 'optionValue' - Null or not Object.

$(function() {
    $('#selectBrand').change(function(){
        $.getJSON('Scripts/ajax_busquedas.php', {idMarca : $(this).val() }, function(j) {
            var options = '';
            var i = '';

            for (i = 0; i < j.length; i++) {
                options += '<option value="' + j[i].optionValue +'">' + j[i].optionDisplay + '</option>';
            }

            $('#selectCategory').html(options);
            $('#selectCategoy option:first').attr('selected', 'selected');
        });
    });
});

      

Any ideas on how I can get started debugging this?

Thanks Max

+2


source to share


2 answers


Check your Json for example:

{"property1": 1, "property2":2,/*<-- see the extra 'trailing comma' */};

      



works in firefox, safari, etc, but gives erros in IE.

+2


source


Make sure you define optionValue

and optionDisplay

either in the scope of the JSON call or define them as global variables:



var optionValue = '';

      

0


source







All Articles