brazenskies
07-13-2009, 11:09 AM
In the past I have used ajax successfully with asp but wehn I use exactly the same code with a php application it runs incredibly slowly...
Here is my ajax. I have simplified the php file to rule out any slowness coming from an sql query
function createRequestObject() {
var ro;
if (window.XMLHttpRequest) {
ro = new XMLHttpRequest();
}else if (window.ActiveXObject) {
try {
ro = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ro = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
return ro;
}
function dictionary() {
if (document.getElementById("location").value == ""){
document.getElementById("dictionary").style.display = 'none';
}else{
document.getElementById("dictionary").style.display = 'block'
var theInput = document.getElementById("location").value;
var theType= document.getElementById("searchType").innerHTML;
http = createRequestObject();
http.open('get', 'dictionary.php');
http.onreadystatechange = handleDictionaryResponse;
http.send(null);
document.getElementById("dictionary").innerHTML = '<img src="images/loader.gif"/ >'
}
}
function handleDictionaryResponse() {
if(http.readyState == 4){
var theResponse = http.responseText;
document.getElementById("dictionary").innerHTML = theResponse;
}
}
and here is the very basic contents of my php file...
echo 'hello, world!';
When I call the ajax using...
<input type="text" name="location" id="location" value="" onkeyup="dictionary()"/>
..it runs successfully, without fail but it takes up to 5 or 6 seconds to return "Hello, world!" to the screen.
I decided to use a simple asp file to see if it makes any difference...
response.write("Hello, world!")
I changed the red line above to "dictionary.asp" and it runs instantly without any delay whatsoever.
Has anyone else experience any issues like this with php?
Thanks in advance!
Here is my ajax. I have simplified the php file to rule out any slowness coming from an sql query
function createRequestObject() {
var ro;
if (window.XMLHttpRequest) {
ro = new XMLHttpRequest();
}else if (window.ActiveXObject) {
try {
ro = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ro = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
return ro;
}
function dictionary() {
if (document.getElementById("location").value == ""){
document.getElementById("dictionary").style.display = 'none';
}else{
document.getElementById("dictionary").style.display = 'block'
var theInput = document.getElementById("location").value;
var theType= document.getElementById("searchType").innerHTML;
http = createRequestObject();
http.open('get', 'dictionary.php');
http.onreadystatechange = handleDictionaryResponse;
http.send(null);
document.getElementById("dictionary").innerHTML = '<img src="images/loader.gif"/ >'
}
}
function handleDictionaryResponse() {
if(http.readyState == 4){
var theResponse = http.responseText;
document.getElementById("dictionary").innerHTML = theResponse;
}
}
and here is the very basic contents of my php file...
echo 'hello, world!';
When I call the ajax using...
<input type="text" name="location" id="location" value="" onkeyup="dictionary()"/>
..it runs successfully, without fail but it takes up to 5 or 6 seconds to return "Hello, world!" to the screen.
I decided to use a simple asp file to see if it makes any difference...
response.write("Hello, world!")
I changed the red line above to "dictionary.asp" and it runs instantly without any delay whatsoever.
Has anyone else experience any issues like this with php?
Thanks in advance!