【问题标题】:Can't load Select from Ajax with IE9无法使用 IE9 从 Ajax 加载选择
【发布时间】:2013-12-08 18:33:20
【问题描述】:

我有一个使用 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>");  
        } 
    }

这适用于 Firefox、Chrome、Safari 和 IE10。它不适用于 IE9。

在 IE9 中,选择元素不会填充加载的信息,但我可以看到 getFiles.php 调用返回了正确的数据。调用后选择元素是

有谁知道 IE9 是怎么回事?

谢谢。

【问题讨论】:

  • 你使用哪个 jQuery 版本?
  • 你能展示你用来填充选择列表的代码吗?

标签: html ajax internet-explorer-9


【解决方案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)(与其他浏览器的结果相同)。列表框包含 file1file2

如果你想看到生成的html,你只需要点击刷新按钮(在红色方块中)

希望这是你想要的。

【讨论】:

  • 感谢您将代码放在一起。我希望我给你的时间点。我能够让你的测试在 IE9 上运行,所以我现在应该可以让我的测试工作了。基本方法显然没有错。再次感谢。
  • 很高兴它帮助了你:)
【解决方案2】:

我有同样的问题。更好的方法是引用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

【讨论】:

    猜你喜欢
    • 2016-11-09
    • 2023-04-06
    • 2015-05-16
    • 1970-01-01
    • 1970-01-01
    • 2017-09-16
    • 2011-10-15
    • 1970-01-01
    • 2012-10-27
    相关资源
    最近更新 更多