...

View Full Version : Problem with Returning Large Strings Via Ajax



quakerstate79
12-07-2006, 09:32 PM
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.


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

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


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

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


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

quakerstate79
12-07-2006, 09:36 PM
also, i apologize if this isnt the right forum for this question to be in. (you guys really need an ajax forum imo)

Q

quakerstate79
12-07-2006, 10:37 PM
nobody has any idea?

quakerstate79
12-08-2006, 07:38 PM
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

david_kw
12-08-2006, 08:49 PM
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

VR2
12-09-2006, 01:35 AM
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.

quakerstate79
12-11-2006, 05:11 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum