View Full Version : AJAX Help
Kevinnaia
03-08-2006, 06:45 PM
OK, I have some questions about this. I am new to it, but I get the general idea of it and can pick up fast.
My Site: http://area51.knaia.level6hosting.net/design/index.php
1) The rotating quotes (yellow bar) don't work in IE.
2) I want to use the same script that I have for the rotating quotes to make the header image change randomly (right now it cahnges if you reload the page). I have tried doing it, but I mess it up each time.
3) I want to switch the main page content with AJAX so I can keep the music going. I have the scripts set up, but they aren't working correctly.
Can anyone help me?
Thanks,
Kevin
aluminumpork
03-09-2006, 05:59 PM
I can probably help you, although I cannot see your JS file since it's in an external file. Could you post your source here please?
Kevinnaia
03-09-2006, 06:26 PM
function createRequestObject() {
var req;
if(window.XMLHttpRequest){
// Firefox, Safari, Opera...
req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
// Internet Explorer 5+
req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
// There is an error creating the object,
// just as an old browser is being used.
alert('There was a problem creating the XMLHttpRequest object');
}
return req;
}
// Make the XMLHttpRequest object
var http = createRequestObject();
function sendRequest(act) {
// Open PHP script for requests
http.open('get', 'ajax/ajax.php?act='+act);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4 && http.status == 200){
// Text returned FROM PHP script
var response = http.responseText;
if(response) {
// UPDATE ajaxTest content
document.getElementById("quote").innerHTML = response;
setTimeout(getQuote, 5000);
}
}
}
function getQuote() {
sendRequest('getQuote');
}
function loadurl(dest) {
try {
// Moz supports XMLHttpRequest. IE uses ActiveX.
// browser detction is bad. object detection works for any browser
xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
// browser doesn't support ajax. handle however you want
}
// the xmlhttp object triggers an event everytime the status changes
// triggered() function handles the events
xmlhttp.onreadystatechange = triggered;
// open takes in the HTTP method and url.
xmlhttp.open("GET", dest);
// send the request. if this is a POST request we would have
// sent post variables: send("name=aleem&gender=male)
// Moz is fine with just send(); but
// IE expects a value here, hence we do send(null);
xmlhttp.send(null);
}
function triggered() {
// if the readyState code is 4 (Completed)
// and http status is 200 (OK) we go ahead and get the responseText
// other readyState codes:
// 0=Uninitialised 1=Loading 2=Loaded 3=Interactive
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
// xmlhttp.responseText object contains the response.
document.getElementById("content").innerHTML = xmlhttp.responseText;
}
}
aluminumpork
03-09-2006, 07:17 PM
Well, I could be wrong, as you may be already do this. But I had a similar problem in IE a while ago. It turned out it was cacheing the first result, and only showing that from then on. My solution was to put on my php page:
header('Cache-Control: no-cache');
Make sure that goes above ALL other PHP code.
Give that a shot.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.