select option problem

select option problem

hey guys i'm using
  1. $("#language option[value='ar']").attr('selected','selected');
in my ajax script if successful...but it doesn't select the option...now if i run the same code above at the end of the ajax it works like a dream.

i don't understand what is going on...any ideas please guys...thank you
  1. $(document).ready(function(){
        $("#language").change(function() {
            console.log('changed');
        });
       
        $.ajax({
            dataType: "text",
            url: "http://bisi.bid/language",
            success: function(language) {
                language = language.trim();
                console.log(language);
                $("#language option[value='ar']").attr('selected','selected');
            },
            error: function() {
            }
        });
        // this line works if uncommented
        //$("#language option[value='ar']").attr('selected','selected');
    });