首先,我嘗試了一些類似的帖子,但是找不到任何東西。主要是因爲我在FF中看到這個問題,而不是IE。使用AJAX和PHP時緩存問題(可能)
我有一個網頁更新MySQL數據庫沒有問題的一些數據。然後今天,我改變了這樣做的方式,以便我可以使用ID而不是數值,所以對於尺寸,而不是小,中,大,它是1,2和3.
有問題的網站是here,你可以通過輸入代碼1234進入測試畫廊。
我每次添加到籃子都會得到腳本。
所以下單選按鈕,有值1,2和3
該位的HTML如下:
<input type="radio" name="imageSize" id="imageSize" value="1"/> Small (6x4) - £4.99<br/>
<input type="radio" name="imageSize" id="imageSize" value="2"/> Medium (7x5) - £6.99<br/>
<input type="radio" name="imageSize" id="imageSize" value="3"/> Large (8x6) - £10.99
我已決定爲現在在手代碼它讓它工作。
這被髮送到一個包含JavaScript文件,然後根據從而被髮送到插入頁:
unction createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}
var http = createObject();
/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function insert() {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('insert_response').innerHTML = "Just a second..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var image= encodeURI(document.getElementById('image').value);
var image_Size= encodeURI(document.getElementById('image_Size').value);
alert(image_Size);
alert(nocache);
// Set the random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'insert.php?image='+image+'&imageSize='+image_Size+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = 'Image added:'+response;
}
}
正如你所看到的,無論發生什麼情況,警報彈出說1.即使你選擇中型或大型。這裏發生了什麼?
謝謝。 回想起來我無法相信我犯了這樣一個學校男孩的錯誤。猜猜發生這種事時會發生什麼。 謝謝。 – 2009-11-26 09:27:56