2013-12-08 96 views
0

我有一个选择元素,我用ajax填充文件名。无法加载从IE9与Ajax选择

的HTML是:

<select id='load_dropdown' name=loads help_token="load_dropdown" title=""> 
     <option value='' selected='selected'>LOAD</option> 
</select> 

呼叫填补元素是:

$('select#load_dropdown') .load('getFiles.php', {list : 'LOAD'}); //fill the load drop down list 

getFiles.php:是

$dir = $_SESSION['user']['id'] . "/xmls/";  // files are in xmls dir 
if ($dirHandle = opendir($dir)){ 
} 
else { 
    echo ("<br />getFiles.php: $dir not found."); 
    exit; 
} 

echo ("<option selected='selected' value=''><b> $list </b> </option>"); // first line of this drop down option 
     while (false !== ($fileName = readdir($dirHandle))) { 
      if ($fileName == "." || $fileName == "..") { 
       continue; 
      } 
      $fileNames[] = $fileName;  // collect file names 
     } 

     sort($fileNames); 
     foreach ($fileNames as $fileName) { 
      $displayName = basename($fileName, '.xml');  // cut .xml at end 
      echo ("<option value='$displayName'>" . $displayName . "</option>"); 
     } 
    } 

这工作得很好了火狐,Chrome, Safari和IE10。它不适用于IE9。

使用IE9 select元素不会填充已加载的信息,但我可以看到getFiles.php调用正在返回正确的数据。在通话结束后,选择元件

enter image description here

有谁知道这是怎么回事用IE9?

谢谢。

+0

你使用哪个jQuery版本? –

+0

你可以显示你用来填充选择列表的代码吗? – cdlong

回答

1

什么是你的jQuery的版本? 我已经测试此代码1.9.1和1.10.2:

getFiles.php:

<?php 
//$dir = $_SESSION['user']['id'] . "/xmls/";  // files are in xmls dir 
$dir = 'xmls/'; // for testing 
if ($dirHandle = opendir($dir)){ 
} else { 
    echo ("<br />getFiles.php: $dir not found."); 
    exit; 
} 
echo ("<option selected='selected' value=''><b> $list </b> </option>"); // first line of this drop down option 
while (false !== ($fileName = readdir($dirHandle))) { 
    if ($fileName == "." || $fileName == "..") { 
     continue; 
    } 
    $fileNames[] = $fileName;  // collect file names 
} 

sort($fileNames); 
foreach ($fileNames as $fileName) { 
    $displayName = basename($fileName, '.xml');  // cut .xml at end 
    echo ("<option value='$displayName'>" . $displayName . "</option>"); 
} 

get_files.html

<script src="jquery-1.10.2.min.js" type="text/javascript"></script> 

<select id='load_dropdown' name=loads help_token="load_dropdown" title=""> 
     <option value='LOAD' selected='selected'>LOAD</option> 
</select> 

<script> 
    $('select#load_dropdown').load('getFiles.php', {list : 'LOAD'}); //fill the load drop down list 
</script> 

我创建了一个xmls项目根目录中的文件夹file1.xmlfile2.xml

它适用于IE9(版本9.0.8112。更新9.0.24)(与其他浏览器的结果相同)。列表框包含file1file2IE9 - load

如果你想看到生成的HTML,你中庸之道必须单击刷新按钮(红色正方形)

希望这是你想要的。

+1

感谢您将代码放在一起。我希望我能及时给你。我能够让你的测试在IE9上运行,所以我应该能够让我的工作现在。基本方法显然没有错。再次感谢。 – Steve

+0

很高兴帮助你:) – onionpsy

1

我有同样的问题。更好的方法是引用divspan元素:

<div id="select"><select id='load_dropdown' name=loads help_token="load_dropdown" title=""> 
    <option value='' selected='selected'>LOAD</option> 
</select> 
</div> 

-

$('#select #load_dropdown') .load('getFiles.php', {list : 'LOAD'}); //fill the load drop down list