【发布时间】:2012-02-11 18:35:24
【问题描述】:
我有一个在表格中显示 XML 信息的页面。 XML 文件是服务器端的,我使用 PHP 使用下拉框获取文件名和数据。 JSON 用于将名称放在下拉列表中,而 DOM 用于发送 XML。这在所有浏览器中都可以正常工作。
我的添加条目功能存在问题。当我在 Chrome 或 Firefox 中添加条目时,它会在下次选择该表时显示。但它在 IE9 中不起作用。这些条目已添加到 xml 文件中,但要在 IE 中查看这些更改,我必须打开一个新选项卡。简单的刷新是行不通的。要在这个脚本中重定向,我使用了 header 函数:
header('Location: ./client2.html');
这里是否需要为 IE 添加一些内容,或者其他地方是否存在问题。我添加了在选择文件时获取数据的 php。
ini_set('display_errors',1);
error_reporting(E_ALL);
/* gets the selected file to use to return data */
$xml_filename = './XML/'.$_REQUEST['file'];
$xml = simplexml_load_file($xml_filename);
/* gets the root of the selected file */
$rootname = $xml->getName();
/* gets the children in that root */
$children = $xml->children();
$firstchild = $children[0];
// gets the table headings
$data = '{"headings":[';
foreach ($firstchild as $elem)
{
$data = $data.'"'.$elem->getName().'",';
}
// removes trailing ','
$data = substr_replace($data,"",-1);
$data = $data.'],';
// gets the cell values
$data = $data. '"vals":[';
foreach ($children as $child)
{
$data = $data.'[';
foreach ($child as $elem => $vals)
{
$data = $data.'"'.$vals.'",';
}
$data = substr_replace($data,"",-1);
$data = $data.'],';
}
// removes trailing ','
$data = substr_replace($data,"",-1);
$data = $data.']}';
/* sends created JSON string back to client */
echo $data;
【问题讨论】:
-
我就是这么想的。你知道有什么方法不允许浏览器在页面上缓存吗?
-
原来是缓存问题。我可以修复它的唯一方法是将
$.ajaxSetup({cache:false})放在文档准备好的 Ajax 中。
标签: php javascript json internet-explorer-9