Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

While sending data by ajax, data gets lost

I'm working on a project where I've developed a website for a travelagency. Things are getting better and more traffic is being generated. The problem lies in slow generated pricetables. Me and my clients figured, because of the available funds, memcache should do the trick. Exited as I was to get started I've rewritten old ajax-code by new jQuery ajax code. Some other posts from this evening are a bit covering this topic.

Now I have the following code which shows a pricetable for a certain month:

function ShowPriceTable(targetElement, accommodationID, month)
{
    $.ajax({
        type:   "POST",
        url:    basePath + "/ajax/GetPriceTable.php",
        data:   "accommodationID="+accommodationID+"&month="+month,
        success: function(data){
            $("#"+targetElement).html(data);

            $.ajax({
                type:   "POST",
                url:    basePath + "/ajax/WriteCache.php",
                data:   "accommodationID="+accommodationID+"&month="+month+"&data="+data,
            });
        }
    });         
}

GetPriceTable.php is a large file, executing many queries and a lot of pricecalculation is done there. It all results in an HTML-table with prices. That output, stored in data is injected in the innerHTML property of a div, in this case targetElement because it must be adjustable.

I figured, well.. when I have the correct output in data I just fire another call to WriteCache.php with the data. The data then gets stored in the memcache server by $cache->set("my_key", $_POST["data"]); (headers are used and set to the past to ensure a 'new' visit for the browser).

Now comes the tricky part... no matter what I try, I only get EXACTLY 4067 characters in my cache. I've run out of options I can think of. This is only a small part of the total output... Addition, an alert of data.length showed me in the pricetable for the accommodation I'm looking in, the length is 98.858.

Do you have any suggestion what might be causing this strange behavior? Can it be the data is passed bit by bit? Memcache has an option chunk_size, by default it is set to 8192 (bytes I guess?, the documentation doen't tell..)

Any help is greatly appreciated!

Cheers!

P.s. the tag memcached must be memcache but I can't choose that option..

Update The problem is irrelevant to memcache. For some reason my data get's changed while it's being sent again. This results into invalid HTML which, for some reason, is not set into the cache and not displayed in my output (mail to myself) but when I output the result (using success: in the second call) to another DIV I do see the 'mangled' output...

like image 252
Ben Fransen Avatar asked Nov 13 '22 16:11

Ben Fransen


1 Answers

I've figured it out, it took me all evening though... My output contains HTML entities. And you've guessed it. HTML entities start with an ampersand which at the same time is the delimeter-character for data retreived by $_GET, $_POST or $_REQUEST. A simple escape(data) did the trick. Thanks for all who took the time to digg into this!

like image 112
Ben Fransen Avatar answered Dec 10 '22 10:12

Ben Fransen