views:

164

answers:

2

Hi, 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

+2  A: 

Check your Json, things like :

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

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

Cleiton
What exactly is wrong in IE with this JSON? The spacing?
mistero
This is my JSON: $resultado .= "{optionValue: $id, optionDisplay: '$marca'},";
mistero
no no, the extra " , "
Cleiton
well as you can see i dont have that. might there be an issue with IE not reaching because of htaccess password?
mistero
'$marca'},"; <-- But you have!
Cleiton
look your generated json, it is probrally tha last braket has a extra * , * (i'm sorry I dont kno whow to call it LOL)
Cleiton
oh so the one outside the {} also counts?
mistero
[ {'optionValue': 0, 'optionDisplay': '-categorias-'},{'optionValue': 89, 'optionDisplay': 'Accesorios'},{'optionValue': 85, 'optionDisplay': 'Cámaras Digitales'}, ]
mistero
of course, if i'm not wrong, jquery parser your json with something like "({" + code_santinized + "})"
Cleiton
see, you have a array with the last element ends with a " , " (please someone tell me how could i call it)?
Cleiton
you are right the last one ,] :D now i need to fix it haha
mistero
you can call it a trailing comma
mistero
@mschoening, thanks!
Cleiton
A: 

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

var optionValue = '';
James Skidmore