Dynamic dropdown in mootools is not getting populated in IE7. Working fine in IE8

661 views Asked by At

I am firing an ajax call to get json response which I am populating in the dropdown.

Code is:

var ajaxURL = "abc.ajax";
var fireAjax = new Request.JSON({
    url: ajaxURL,
    method:'GET',
    onSuccess:function(resultjson){

                if(resultjson.length!=0){
                    var elSelect = new Element('option',{'html':'First component','value':'All'}).injectInside($('vehicletype'));
                    resultjson.each(function(vName){

                    var elOptions = new Element('option',{'value':vName,'selected':'selected' }).setHTML(vName).injectInside($('vehicletype'));


                    });

                    sschecker[0].registerAnotherElement($('vehicletype'));


                }

            }


}).send();  

This is working fine in IE8, firefox, etc.

1

There are 1 answers

1
pleasedontbelong On

There is no reason why it shouldn't work on IE7 (even IE6).

I've tested it (and changed a few things) of your code:

var ajaxURL = "/echo/json/";
var fireAjax = new Request.JSON({
    url: ajaxURL,
    method:'POST',
    data: {
        json: JSON.encode({
            opt1: 'option 1',
            opt2: 'option 2'
        })
    },
    onSuccess:function(resultjson){
                if(resultjson.length!=0){
                    var elSelect = new Element('option',{'html':'First component', 'value':'All' }).injectInside($('vehicletype'));
                   Object.each(resultjson,function(value,key){
                       new Element('option',{'value':key,'html':value}).inject($('vehicletype'));
                       //sschecker[0].registerAnotherElement($('vehicletype'));
                   });

                }
            }
}).send();  

I've changed the method to POST and added the data.. just to be able to test it in jsfiddle http://jsfiddle.net/F7G9Y/2/.. its working on IE7 (don't have IE6 sry)

in my opinion (and my experience), it's usually due to a malformed JSON, most of the time because of an extra coma. So json strings like this :

{ 
  'foo':'Foo',
  'bar':'Bar', //<-extra coma here
}

will be ok in Firefox, Chrome but not on IE

Hope this helps