Take the 2-minute tour ×

Good Morning,

I have a really simple script that works fine on everything but IE. I'm populating a dropdown menu with information from a database using an XML response in the following format:


I'm getting this data like so:

var options = $.ajax({
          url     :   "/static/scripts/php/search.php",
          type    :   "POST",
          data    :   {search_key :   key}

And the response is coming back just fine, regardless of browser. IE and Chrome alert the response text the same.

But when I do:

 $(options).find('option').each(function() {
         var option = document.createElement('option');
         $(option).attr("value", $(this).text()).text($(this).text());

IE never enters the each() loop, meaning it's not finding "option" in the response text. I'm at my wit's end with this. It's too simple of a script to be spending this much time on. Any help?

I've run the script through JSLint looking for small, odd items, and it's clean.



share|improve this question

1 Answer 1

up vote 1 down vote accepted

responseText is a string, try parsing it as xml first.

options = $.parseXml(options);

Also, generally you don't want to use the response text in that way. It is usually best to use the done callback or success callback.

  url: "url",
  dataType: "xml", // so that it will auto parse it as xml
  success: function(xml){
    // do something with xml


  url: "url",
  dataType: "xml" // so that it will auto parse it as xml
  // do something with xml
share|improve this answer
Changing it to a callback worked. It got extra mad when I tried parseXml. Thanks. –  Tom Thorogood Dec 12 '11 at 15:19
When you use the response text the way you were, it should return undefined because the request hadn't been made yet. –  Kevin B Dec 12 '11 at 15:21
I use async:false in the ajax call. I know that doing that means I may as well just render it all via PHP, but the jquery syntax is just a lot easier to contend with, and the boss wanted it superfast. It's just something used internally by my dept. –  Tom Thorogood Dec 12 '11 at 15:24
Granted, that shortcut wound up not being so short after all. /grin –  Tom Thorogood Dec 12 '11 at 15:25
As far as why it didn't work by simply using $(xml) where xml is your xml string, using $(xml) parses the xml as html. Since the tags used within are not valid html elements, IE ignores them. –  Kevin B Dec 12 '11 at 15:32

Your Answer


