Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2008
    Location
    Oxford, UK
    Posts
    422
    Thanks
    14
    Thanked 27 Times in 27 Posts

    Slow running ajax with php

    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

    Code:
    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...

    Code:
    echo 'hello, world!';
    When I call the ajax using...

    Code:
    <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...

    Code:
    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!

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Oxford, UK
    Posts
    422
    Thanks
    14
    Thanked 27 Times in 27 Posts
    I fear that this might have something to do with how php was configured on IIS


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •