Hej folks
Jeg har et problem jeg er ved at hive mig i håret over. FF (3.03)
cacher på en eller anden måde mit kald til min ajax side (der bare
skriver "response" (ren debug mode, har barbereret alt væk i debuggens
hellige navn)) og returnerer først gang response men næste gang er
return tomt. Jeg har prøvet med et link, der direkte kalder funktionen
og her kommer der, det ønskede hver eneste gang.
Her er brudstykker af koden:
function userAction(action) {
var ajaxRequest; // The variable that makes Ajax possible!
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function() {
if(ajaxRequest.readyState == 4) {
var ajaxDisplay = document.getElementById('AjaxContainer');
alert("response:" +ajaxRequest.responseText);
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
// cach workaround - no result
function noCache(uri){return uri.concat(/\?/.test
(uri)?"&":"?","noCache=",(new Date).getTime(),".",Math.random()
*1234567)};
// cache workaround - no result
var myRand=parseInt(Math.random()*99999999);
if(action == "update_password") {
var password = document.getElementById('password').value;
var password2 = document.getElementById('password2').value;
var queryString = "?password=" + password + "&password2=" +
password2 + "&action=" + action;
}
else if(action == "test") {
var queryString = "?action=" + action;
}
//queryString += "&myRand=" + myRand
alert(queryString);
ajaxRequest.open("GET", noCache("ajax-users3.php") + queryString,
true);
ajaxRequest.send(null);
}
function passwordForm() {
var form = '<h3>Change password:</h3>'
form += '<form name="passwordForm" method="get">'
form += '<b>Password:</b><br />'
form += '<input type="password" id="password" /> <br />'
form += '<b>Retype password:</b><br />'
form += '<input type="password" id="password2" /> <br />'
form += '<input type="submit" id="submit" onclick=\'userAction
("update_password")\' /> <br />'
form += '<form>'
var myform = document.getElementById('AjaxContainer');
myform.innerHTML = form;
}
//-->
</script>
<div id='AjaxContainer'><a href="#" onclick='passwordForm()'>Change
password</a> - <a href="#" onclick='userAction("test")'>test</a></div>
Jeg har også smidt en masse headers ind i PHP:
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache')
men lige lidt hjælper det :-/
Jeg er nok ikke den eneste, der har haft dette problem, så måske
sidder en lige med de vise sten og det ville være top, for jeg har
godt nok ikke brug for en frisør efter idag
AJAX er forholdsvist
nyt for mig, men jeg skulle mene at jeg har lavet ovenstående korrekt?
Dump fra Live http headers, som man kan se så henter den korrekt fra
ajax-users3.php først gang, men næste gang lader det til at den tilgår
sig selv (my_account.php):
http://mydomain.com/my_account.php
GET /my_account.php HTTP/1.1
Host: mydomain.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
1.9.0.3) Gecko/2008092417 Firefox/3.0.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer:
http://mydomain.com/my_account.php
HTTP/1.x 200 OK
Date: Wed, 12 Nov 2008 15:09:35 GMT
Server: Apache/2.2.6 (Win32) PHP/5.2.4
X-Powered-By: PHP/5.2.4
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-
check=0
Pragma: no-cache
Last-Modified: Wed, 12 Nov 2008 15:09:35 GMT
Content-Length: 2936
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
http://mydomain.com/ajax-users3.php?password=teagd&password2=gddfgds&action=update_password&myRand=53771791
GET /ajax-users3.php?
password=teagd&password2=gddfgds&action=update_password&myRand=53771791
HTTP/1.1
Host: mydomain.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
1.9.0.3) Gecko/2008092417 Firefox/3.0.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer:
http://mydomain.com/my_account.php
HTTP/1.x 200 OK
Date: Wed, 12 Nov 2008 15:09:25 GMT
Server: Apache/2.2.6 (Win32) PHP/5.2.4
X-Powered-By: PHP/5.2.4
Content-Length: 15
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
----------------------------------------------------------
http://mydomain.com/my_account.php
GET /my_account.php HTTP/1.1
Host: mydomain.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
1.9.0.3) Gecko/2008092417 Firefox/3.0.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer:
http://mydomain.com/my_account.php
HTTP/1.x 200 OK
Date: Wed, 12 Nov 2008 15:09:31 GMT
Server: Apache/2.2.6 (Win32) PHP/5.2.4
X-Powered-By: PHP/5.2.4
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-
check=0
Pragma: no-cache
Last-Modified: Wed, 12 Nov 2008 15:09:31 GMT
Content-Length: 2936
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
--
mvh
Kim Emax