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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    $.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!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Location
    Sweden
    Posts
    154
    Thanks
    1
    Thanked 22 Times in 22 Posts
    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...

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.


  •  

    Posting Permissions

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