I'm writing a wrapper for the UC Ajax Cart module so the dynamic shopping cart can be used with Authcache.

I have the basic stuff working. If I have my module do nothing but return a hardcoded value, all is good and Authcache will populate the block with that value.

However, if I call the uc_price function within my code, even if I ignore what uc_price is returning and return the exact same hardcoded value as before ('test'), nothing gets updated in the page. What's odd is the uc_price function appears to work fine, and returns the correct value, and I can step through all of the code all the way up through the JSON encoded response being printed. What is not happening though, is the "success" method of the jquery ajax object is not getting called. Does this mean that PHP is returning some kind of an error response even through I can't see it and the code appears to execute cleanly?

Is there any way I can get more information about what's going on? I have debugging turned on in Authcache settings but it doesn't seem to include any information about Authcache contrib modules (including the Authcache example module).

Many thanks.

#5 authcache_ajax.patch6.75 KBadamo
Members fund testing for the Drupal project. Drupal Association Learn more


adamo’s picture

I run into the same issue if I try a full Drupal bootstrap (just the bootstrap, then returning a hardcoded string, not executing uc_price or anything else). The jquery ajax "success" function doesn't get executed. But I can step through the entire PHP code and everything looks fine. If I could do a full Drupal bootstrap I think that calling uc_price wouldn't be a problem.

Any ideas why a full Drupal bootstrap doesn't work?

adamo’s picture

OK, I dug a little deeper. The problem is if I do a full bootstrap the Authcache footer JSON (wrapped in script tags) gets printed along with the JSON from the ajax request. It seems like _authcache_shutdown_save_page() should only be executed when a full page is being returned and not for an ajax request. I'm not sure the best way to check for that.


mths’s picture

Please, how do I stop receiving emails from this thread?

adamo’s picture

Title: Writing a contrib module, hitting a wall. » "Authcache Footer JSON" text being appended to ajax JSON when full bootstrap is done.
Category: support » bug
Status: Active » Patch (to be ported)

@mths: I have no idea.

I solved the problem with the "Authcache Footer JSON" getting appended to the JSON response for ajax requests when a full bootstrap is done.

At the top of authcache.php I added:

global $is_ajax_authcache;

Then in authcache_helpers.php, at the top of _authcache_shutdown_save_page():

  global $user, $base_root, $is_page_authcache, $is_ajax_authcache;

  // We don't want this code to run for ajax requests
  if ($is_ajax_authcache) {

Patch attached. Changing this to a bug report. I still have a problem with full bootstrap failing half the time, but I'll put that in another issue.

adamo’s picture

6.75 KB

Oops... Looks like the patch didn't get uploaded for some reason...

adamo’s picture

Status: Patch (to be ported) » Needs review

Any chance of getting this patch commited?

vood002’s picture

I'm having related issues on my site. Both the Vote UpDown module and PECL Uploadprogress bar fail when authacache is enabled. Vote UpDown fails when a user votes, and the response attempts to update the "vote count". PECL uploadprogress failes immediately, throwing an error like:

An error occurred. /filefield/progress/b3ddc1019e36bf918eaa4a534013f748 { "message": "Starting upload...", "percentage": -1 } <!-- Authcache Footer JSON --> <script language="JavaScript"> var authcacheFooter = { "info": { "page_render": 626.64, "cache_render": "-1", "cache_uid": "23", "cache_inc": "cacherouter.inc (db)", "cache_time": 1261415297 }, "ajax": { "q": "filefield/progress/b3ddc1019e36bf918eaa4a534013f748", "statistics": 1 } }; </script>

I applied the patch in #5 to Authcache RC1 but I'm still getting the same errors, the errors disappear when I use user#1.

Any idea if this patch could be modified to fix these errors?

mikec’s picture

@vood002, I had the same problem you did with the PECL uploadprogress bar and Authcache. I fixed it by adding the line:


to my "Cache every page except the listed pages" list on the Authcache Page Caching Settings page (admin/settings/performance/authcache/pagecaching).

vood002’s picture

thanks mikec....i'll experiment with this and see where it takes me

Jonah Ellison’s picture

Assigned: Unassigned » Jonah Ellison
Status: Needs review » Fixed

Patch from #4 committed in RC2. Also added an additional check to prevent Ajax requests from being cached and the footer JSON added. Thanks guys.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

kentr’s picture

@Jonah Ellison

Also added an additional check to prevent Ajax requests from being cached

Curious why you don't want AJAX requests being cached. In my mind, there are a lot of AJAX cases in which caching would help.

Jonah Ellison’s picture

kentr -- Ajax requests usually return user-specific data (e.g. from this thread, it's upload progress and ubercart), and many people have experienced issues with caching Ajax.

There are probably some cases where it may be helpful... it may be beneficial to have the option to cache Ajax requests (instead of completely disabling it by default). I'll look into adding this to the next release.

kentr’s picture

Awesome & thanks for the reply.

Mainly I'm thinking of Ajax views. In my case, for an Ajax version of views_slideshow.

If I have some time, I'll put some thought into a way to make this optional.

Edit: As I thought a little more about this, I wondered... If a module explicitly uses caching (like Views), does that use Authcache, and will the caching still happen if it's an Ajax request?