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 7 of 7
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with Returning Large Strings Via Ajax

    Hey guys, I have a web app that has a javascript front end, a php back end. The javascript calls the php function which queries a database, and sends the information from the database, in string form, back to the javascript, which parses the string and displays the info. This works great until the data returned from the php script reaches a strlength of about 500,000 or so. Then it doesnt return anything, or it returns this message.

    Code:
    D4 Date: Wed, 06 Dec 2006 21:25:45 GMT Server: Apache/2.0.52 (Unix) mod_ssl/2.0.52 OpenSSL/0.9.7d DAV/2 PHP/5.0.4-dev X-Powered-By: PHP/5.0.4-dev Keep-Alive: timeout=15, max=97 Connection: Keep-Alive Content-Ty 0
    here's the relevant bits of code:

    the javascript function
    Code:
    if(searchablerequest)
    		{
    			postDataReturnText("./phpscripts/searchDB.php",'data='+passedstring, doDisplayResults);
    
    			var loading = document.createElement('DIV');
    			loading.id = "loadingdiv";
    			loading.innerHTML = "Loading Search Results...";
    			loading.style.width="200px";
    			var results = document.getElementById("results_div");
    			results.appendChild(loading);
    
    
    		}
    heres the ajax function
    Code:
    function postDataReturnText(url, data, callback)
    	{
    		var XMLHttpRequestObject = false;
    
      		if (window.XMLHttpRequest)
      		{
        		XMLHttpRequestObject = new XMLHttpRequest();
      		}
      		else if (window.ActiveXObject)
      		{
        		XMLHttpRequestObject = new
        		 ActiveXObject("Microsoft.XMLHTTP");
      		}
    
      		if(XMLHttpRequestObject)
      		{
        		XMLHttpRequestObject.open("POST", url);
     			XMLHttpRequestObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    
        		XMLHttpRequestObject.onreadystatechange = function()
        		{
    
        	  		if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
        	  		{
        	      		callback(XMLHttpRequestObject.responseText);
        	      		delete XMLHttpRequestObject;
        	      		XMLHttpRequestObject = null;
        	  		}
    
        	  		
        		}
    
        		XMLHttpRequestObject.send(data);
      		}
    	}
    heres the relevant bit of php code
    Code:
    while($row = mysql_fetch_array($result, MYSQL_BOTH))// add all the individual row info to the return string
    	{
    
    				$feedback.=$row['CaseID'].$delimiter2.$row['CaseTitle'].$delimiter2;//for mail subject line
    
    
    		$color = getCrispColor($row);
    
    		$feedback .= $color.$delimiter2;
    
    		if($all_columns_flag)
    		{
    			foreach($columnlist as $value)
    			{
    				if($value != "CaseHistory")
    				{
    					$feedback.=$row[$value].$delimiter2;
    
    				}
    				else $feedback.=$row['CaseID'].$delimiter2;
    
    			}
    		}
    		else
    		{
    			for($i=0;$i<$count2;$i++)
    			{
    				if($columns_to_display[$i] != "CaseHistory")
    				{
    					$feedback.=$row[$columns_to_display[$i]].$delimiter2;
    				}
    				else $feedback.=$row['CaseID'].$delimiter2;
    			}
    		}
    		$feedback.=$delimiter;
    		
    	}
    	$n = strlen($feedback);
    	$feedback = substr($feedback,0,$n-3);
    	
    
    	echo $feedback;
    and heres the javascript function that handles the php results

    Code:
    function doDisplayResults(results)
    	{
    
    		
    		alert(results);
    
     }
    like i said when the strlength in the php is over 500,000 or so, nothing gets passed to doDisplayResults . And it returns pretty fast with nothing as the result. This leads me to believe that the there is a limit set somewhere in my setup that puts a block on a string return that large. However, I've looked and looked at my httpd.conf/php.ini/appcode till my eyes are bleeding. Something else outside my knowledge is going on here. Any suggestions for alternate lines of investigation i could try?

    Sincerely,

    Q

  • #2
    New Coder
    Join Date
    Sep 2006
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    also, i apologize if this isnt the right forum for this question to be in. (you guys really need an ajax forum imo)

    Q

  • #3
    New Coder
    Join Date
    Sep 2006
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    nobody has any idea?

  • #4
    New Coder
    Join Date
    Sep 2006
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lots of views, no one has any idea? am i asking the wrong question? I know there are some Ajax gurus that frequent these boards. Give a true believer some help.

    Q

  • #5
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm far from an ajax guru and don't know the answer, but I'd probably start by testing the URL outside of ajax and make sure it is returning what you expect it to return. Your code will do nothing if the server returns an error which is what got me thinking in that direction.

    If the URL is returning the correct stuff then I'd probably try checking the readyState in different browsers (since they have different implementations). Technically readyState=2 means the request has been sent and readyState=3 means a partial response has been received.

    I think one of the browsers implemented these correctly (I can't remember which one) but most didn't which is the reason you typically only check for readyState=4. But for debugging purposes it might help.

    And of course I'd try using

    www.getfirebug.com

    which is awesome and lets you track ajax requests. Of course a 0.5M ajax return might give it problems but it's worth a shot. If you try it and like it please donate so Joe is encouraged to keep fixing bugs.

    That's what I'd do next at least.

    david_kw

  • #6
    VR2
    VR2 is offline
    New Coder
    Join Date
    Jul 2006
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Firebug is your friend here as the previous poster has said.

    This sounds like it may well be a Web Server setting in that it will only deliver files of under a certain content length. I saw something very similar in IIS when I had a script that would "BinaryWrite" binary files to the browser - anything over 4MB and it choked - changing an IIS setting solved everything.

  • #7
    New Coder
    Join Date
    Sep 2006
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm, curious. Well, i know its returning, but i'll look into that app to see whats going on in more detail. I'll post my solution once i find one. Thanks for the help so far guys

    Q


  •  

    Posting Permissions

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