Chrome/Safari issue - Ajax/Jquery

462 views
Skip to first unread message

sky rocket

unread,
Aug 29, 2011, 4:18:55 PM8/29/11
to play-framework
I have the below div in my html page:

<div id="loading">
<img src="/public/images/loading-bars.gif"/>&nbsp;Loading...
</div>

Wanted to show a loading image till the ajax call is complete. This
works fine in IE or FF but somehow the ajax request prevents the image
from being displayed in Chrome and Safari. It display it 'only after'
the ajax request is complete.

I have tried all options putting it in success function etc etc. Any
idea why image won't show up in chrome or safari. If I take out the
ajax call then the image shows up fine.

$(document).ready(function() {

$.getJSON("@{JTAliasController.getJobCategories()}", function(json) {

$.each(json, function(i,category){

$('.left-category').append('<input type="checkbox" name=cat'+i+'"
class="category-checkbox"/> '+category.categoryName+'<div
class="clearfix"></div>');
$('.center-category').append('<input type="checkbox" name=cat'+i+'"
class="category-checkbox"/> '+category.categoryName+'<div
class="clearfix"></div>');
$('.right-category').append('<input type="checkbox" name=cat'+i+'"
class="category-checkbox"/> '+category.categoryName+'<div
class="clearfix"></div>');
});

})
.error(function() { alert("Unable to load categories"); })
})
.complete(function() {jQuery("#loading").hide();})

});

Marius Andra

unread,
Aug 29, 2011, 5:04:31 PM8/29/11
to play-fr...@googlegroups.com
Hey,

I'm just guessing here, but probably I'm on the right track;

The trouble is that in development mode, play has only one worker that handles incoming requests. From application.conf:

# Execution pool
# ~~~~~
# Default to 1 thread in DEV mode or (nb processors + 1) threads in PROD mode.
# Try to keep a low as possible. 1 thread will serialize all requests (very useful for debugging purpose)
# play.pool=3

I'm guessing your application logic goes as follows:

1) The browser starts loading the ajax request
2) The browser shows the loading div
3) The browser sees an image in the loading div and asks it from the server
4) The server is busy and won't return the image before the ajax request is processed
5) When the ajax request is processed, you won't need the image anymore and the div is hidden again

And thus you just don't see the image.

So try two things:

2) Increase the pool size and see if it shows up. Later put it back to 1 for the same reason as mentioned in the conf file


Cheers,

Marius


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.



sky rocket

unread,
Aug 29, 2011, 6:43:36 PM8/29/11
to play-framework
>>Increase the pool size and see if it shows up. Later put it back to 1 for the same reason as mentioned in the conf file

This solved the problem. Thanks for help. It would have never thought
of this.

Interesting thought how come it worked in IE and FF. Probably the
browser had cached the image. On other note and sorry if its too basic
what is nbprocessor and how can I check whats the limit for my
machine.

Thanks!!
> @mariusandra <http://twitter.com/mariusandra>

Marius Andra

unread,
Aug 30, 2011, 5:07:21 AM8/30/11
to play-fr...@googlegroups.com
Hey,

I guess it's meant "nr of processors" :-)


Marius
Reply all
Reply to author
Forward
0 new messages