Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-03-2011, 06:04 PM   PM User | #1
uibobit
New to the CF scene

 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
uibobit is an unknown quantity at this point
$.post and working with large datasets

Hi,

I am using $.post to retrieve data from mysql and display it in either jqGrid or slickGrid grids. I don't think they are the problem because it fails before they are even called. If my mysql select statement has limit 22, then it works perfectly in either one. If my mysql select statement has limit 23 (or greater), then they both fail and it looks like things fail even before they are invoked. I know that using limit 23 succeeds as a mysql call because if I run the php function from the command line I see the output.

I've tried setting async to false and setting a 5 second timeout, but that didn't help. I'm pretty sure this is a pure javascript issue and not jquery or either grid plugin. I put in alert messages after every line and I know where it fails.

The php script returns json formatted string. Since php is returning a string, not a json object, setting the dataType: json doesn't work.

Here is the code:
Code:
var hoursdata = [];
jQuery.ajaxSetup({async:false, timeout: 5000});
$.ajax({
	type: "POST",
	url: "adminfunctions.php",
	data: {task: "getAllHours"},
	timeout: 5000,
	async: false,
	success: function(data){
		window.hoursdata = eval(data);
		var mylength = Math.min(hoursdata.length, 50);//fails here if data is too large
		for(var i=0;i<=mylength;i++){
			jQuery("#list27").jqGrid('addRowData',i+1,window.hoursdata[i]);
		}
	}
});
The data fails if the returned data is 7,236 bytes (approx) and works if the data is 6,884 bytes. There's going to be close to 5 megs of data returned for the users to work with. Yeah, I know that's a lot of data, but even if I add some filters and only show information for 1 person, I'll have the same problem. Displaying 50 rows should not be a problem, let alone 23.

Any ideas what might be happening?

Thanks!
uibobit is offline   Reply With Quote
Old 10-03-2011, 08:02 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I've returned as much as 100,000 bytes of data (maybe more) using AJAX successfully.

I don't use jQuery, though, so perhaps it's a problem in the jQuery library?

Have you tried just doing a "dump" of the data? Or looking at it with FireBug, before the eval( ) is used on it?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 10-03-2011, 09:47 PM   PM User | #3
ironboy
Regular Coder

 
Join Date: Sep 2011
Location: Sweden
Posts: 154
Thanks: 1
Thanked 22 Times in 22 Posts
ironboy is an unknown quantity at this point
We have things in production that pull up to 5 megabytes per jquery ajax call (async, no specific timeout set). Never had any problem with it.

Try setting your dataType to to "text" and see if it succeeds, if so you probably have an error in your json...
ironboy is offline   Reply With Quote
Old 10-03-2011, 10:29 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Yeah, by "dump" I meant something like this:
Code:
jQuery.ajaxSetup({async:false, timeout: 5000});
$.ajax({
	type: "POST",
	url: "adminfunctions.php",
	data: {task: "getAllHours"},
	timeout: 5000,
	async: false,
	success: function(data){
            document.getElementById("dumpspot").innerHTML = data.replace(/\</g, "&lt;");
        }
...
That way, you dump the response *effectively* as text (by making all tags disappear, so far as HTML is concerned) into some <div> and can easily look at what is being passed.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:59 AM.


Advertisement
Log in to turn off these ads.