Download & Extend

how to support onmouse over json requests?

Project:Boost
Version:6.x-1.x-dev
Component:Caching logic
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Hi

I tried boost yesterday but i found that it doesn't work well with my module

My module logic - on mouse over of any link to user, it did ajax load of some user content profile data (name, age, city) and show it into a popup bubble. On mouse out, the bubble disappear.

With boost correctly enabled, I got javascript erron on mouse over of link to any user account.

Can you please give to me a hint, how to do some exception for this module or this requests?
This is part of code of my module

function userbubble_menu() {
$items = array(); 
$items['userbubble'] = array(
'path' => 'userbubble/ajax',
'page callback' => 'callAjax',
'access arguments' => array('userbubble user access'),
'type' => MENU_CALLBACK,
);
return $items;
}

function callAjax() {
if ( arg(0) && arg(0) == 'userbubble' && arg(1) && arg(1) == 'ajax' && is_numeric(arg(2)) ) {     
  $wanted_user = user_load( array('uid' => arg(2)) );
  $uid = $wanted_user->uid;
}
$loadedUser = user_load(array('uid' => $uid));
$name = $loadedUser->name;      
             
$sql = "SELECT n.nid, n.uid FROM node n WHERE (n.type = 'uprofile' AND $uid = n.uid)";
$result = db_query($sql);
$row = db_fetch_object($result);
$node_loaded = node_load($row->nid);
$sex = content_format('field_profil_pohlavie_2', $node_loaded->field_profil_pohlavie_2[0], 'default', $node_loaded);
$base_path = base_path();
      
printf ( '{ "uid" : "%s", "icon" : "%s", "name" : "%s", "forename" : "%s", "age" : "%s", "from" : "%s", "sex" : "%s", "photo" : "%s", "počet kamarátov" : "%s", "msg_link" : "%s", "profil_link" : "%s" }',  
//get datas from predefined CCK fields
content_format('field_profil_krstne_meno', $node_loaded->field_profil_krstne_meno[0], 'default', $node_loaded),
...
);  
}

Thank you
Igor
http://www.somvprahe.sk

Comments

#1

What are the JS errors (firebug)? Are you doing a post or a get request? Is the menu path userbubble/ajax/* excluded from the boost cache, under Boost cacheability settings?

btw, this looks like it is doing a full drupal bootstrap to get the info, I would recommend refactoring your code so it's faster. See boost_stats.php for a 1/2 done example; and here are some of the issues in regards to this.
#505766: Does this support the Who's online block?
#503628: AJAX Load stats
#506906: Support node read count display

#2

Your server does a GET, means it could be cached by boost... which could be the issue since boost adds in !-- Page cached by Boost @ ... tag to the bottom of almost everything it caches. Looks like drupal is retuning JSON. Could you see if boost is adding the !-- Page cached by Boost @ ... tag to your ajax requests?

firebug output

GET http://www.somvprahe.sk/userbubble/ajax/3889

200 OK
431ms js_b930f....jsmin.js (line 2)
ParamsHeadersPostPutResponseCacheHTMLCookies
Response Headers
Date

Mon, 06 Jul 2009 21:14:37 GMT

Server

Apache

X-Powered-By

PHP/5.2.4-2ubuntu5.6

Expires

Sun, 19 Nov 1978 05:00:00 GMT

Last-Modified

Mon, 06 Jul 2009 21:14:37 GMT

Cache-Control

store, no-cache, must-revalidate, post-check=0, pre-check=0

Vary

Accept-Encoding

Content-Encoding

gzip

Content-Length

237

Keep-Alive

timeout=15, max=98

Connection

Keep-Alive

Content-Type

text/html; charset=utf-8

Request Headers
Host

www.somvprahe.sk

User-Agent

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)

Accept

*/*

Accept-Language

en-us,en;q=0.5

Accept-Encoding

gzip,deflate

Accept-Charset

ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive

300

Connection

keep-alive

X-Requested-With

XMLHttpRequest

Referer

http://www.somvprahe.sk/

Cookie

SESS22ede675e40c1213764c77c57041a0cb=19425f060fb6e337ce444e1888fc9d40; has_js=1

{ "uid" : "3889", "icon" : "/files/male_ikonky/user.png", "name" : "heartbroken", "forename" : "Tomas"

, "age" : "", "from" : "Košice", "sex" : "Muž", "photo" : "/files/imagecache/bublina/files/imagefield

/profilove_fotky/heartbroken/kandidat.JPG", "počet kamarátov" : "****", "msg_link" : "/messages/new/3889"

, "profil_link" : "/user/heartbroken" }

#3

Status:active» postponed (maintainer needs more info)

#4

Hi Miky

thanks for reply.
I am not sure about your question about ajax request - I think that it is exactly what is in firefox output you posted. There is no other info except this:

{ "uid" : "100", "icon" : "/files/male_ikonky/user_female.png", "name" : "mishka", "forename" : "Mishka", "age" : "", "from" : "", "sex" : "Žena", "photo" : "/files/imagecache/bublina//fotky_profil/default/stredne_velke_bez_textu/kacka.jpg", "počet kamarátov" : "****", "msg_link" : "/messages/new/100", "profil_link" : "/user/mishka" }

the code of my ajax request in my module js is this:

  t = this;
        var ajaxUrl = '/userbubble/ajax/' + this.uid;
        if (ajaxCache[ajaxUrl]) {
replyObj = ajaxCache[ajaxUrl];
this.createBubbleContent(replyObj, posX, posY);
} else {
$.get(ajaxUrl, function(data) {
                eval('var replyObj = ' + data);
                ajaxCache[ajaxUrl] = replyObj;
t.createBubbleContent(replyObj, posX, posY);                      
        }, 'json');
}

However, today I found that the bug is in Internet explorer 8, only. (IE 6 and Firefox is ok) So, maybe it is not problem of Boost. (In this case I am sorry for missunderstanding you)

Ithe javascript error in IE 8 was

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
Timestamp: Tue, 7 Jul 2009 05:46:32 UTC


Message: Expected ';'
Line: 20
Char: 180
Code: 0
URI: http://www.somvprahe.sk/files/js/js_effa8de6187b2717c4b52a45edf2fbc6.jsmin.js

Then I turned off Javascript optimizing and minimizing on performance page, but then the new error appears:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
Timestamp: Tue, 7 Jul 2009 05:49:06 UTC


Message: Expected ';'
Line: 54
Char: 17
Code: 0
URI: http://www.somvprahe.sk/sites/all/modules/userbubble/js/userbubble2.js?S

what is weird because the script is running ok. So, it could be really some problem with IE8 javascript engine... I hope so.
I tried use $.post, as you wrote in your first post, and with $.post it works without problems.
I am not sure if there is better to use get or post in my case, or if it the same and there is no performance difference.

With $.post what means without Boost caching, it works fine, what is great. Thanks again. I have own cache for json object, - I add it into object, and if that object exists, I load it without new json request.

Thanks for the info about bootstrap too, I will look at it today, but currently I don't load bootstrap specially (no function for bootstrap in my module), just basic use a module. The id of a user is added into user link or user picture by theme_function - from $account (I did there some small changes). With uid in user link, i can to do on mouse over load user for that uid, by this module and take some info from his profile. But I am beginner in module development, so probably there could be a lot of things done better :)

Thank you again and have a nice day.
Igor

#5

Status:postponed (maintainer needs more info)» closed (fixed)

try adding a ; to the end of your eval statement, it could fix the error.
eval('var replyObj = ' + data + ';'); //line 54
In any case this doesn't belong on boosts issue queue; if your encountering more issues with your module, I recommend asking for help in the support forum. Default is a full bootstrap; all I'm saying is your server is melting from load, I would look into using a lighter bootstrap in your module.