mistero
mistero

Reputation: 5309

jQuery Error IE JSON

when I run this JS in FF or Safari it works just right but in IE I get 'optionValue' is Null or not an 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 start debugging this?

Thanks, Max

Upvotes: 2

Views: 309

Answers (2)

Cleiton
Cleiton

Reputation: 18113

Check your Json, things like :

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

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

Upvotes: 2

James Skidmore
James Skidmore

Reputation: 50298

Make sure you define optionValue and optionDisplay either within the scope of JSON call or define them as global variables like so:

var optionValue = '';

Upvotes: 0

Related Questions