2012-02-11 60 views
0

我有一個頁面顯示錶中的XML信息。 XML文件是服務器端,我使用PHP來使用下拉框來獲取文件名和數據。 JSON用於將下拉列表中的名稱和DOM發送到XML中。在所有瀏覽器中都能正常工作。PHP IE9 XML問題

我的添加條目功能存在問題。當我在Chrome或Firefox中添加條目時,它會在下次選擇該表時顯示。但它在IE9中不起作用。這些條目被添加到XML文件,但要在IE中查看這些更改,我必須打開一個新的選項卡。簡單刷新不起作用。要在此腳本重定向我用頭功能:

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; 
+0

聽起來像一個緩存問題? – 2012-02-11 18:43:16

+0

這就是我的想法。你知道有什麼方法不允許瀏覽器在頁面上緩存嗎? – 2012-02-11 18:49:15

+0

原來這是一個緩存問題。我可以解決這個問題的唯一方法是將'.ajaxSetup({cache:false})'放在文檔就緒的Ajax中。 – 2012-02-16 13:42:35

回答

0

原來這是一個緩存的問題。我不得不將這個:$.ajaxSetup({cache:false})添加到JavaScript的document.ready()部分。似乎沒有其他工作

+0

您也可以附加一個隨機值的請求,以便瀏覽器將其視爲新文件。 – 2012-02-16 19:12:09

0

如果它是一個緩存的問題,你可以嘗試在header()通話添加一個隨機字符串,像這樣:

$random_str = sha1(uniqid(mt_rand(), true)); 
header('Location: ./client2.html?' . $random_str); 
exit(); 
+0

將隨機數據添加到網址以解決緩存問題並非最佳解決方案。 正確的方法是使用[Cache-control http header](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9) – remy 2012-02-11 19:00:46

+0

我不認爲它是緩存問題,因爲我用你的解決方案,仍然有同樣的問題。 – 2012-02-11 19:10:36

+0

我已經添加了在下拉值更改時獲取數據的php。也許這是一個問題。我試過隨機字符串和緩存控制解決方案都無濟於事。 – 2012-02-11 19:19:11