I want to display some Amazon products downloaded through Ajax.
I call the method below using Ajax, but the request takes a couple of seconds.
@items = []
@shows.shuffle.first(5).each do |show|
req = AmazonProduct["us"]
req.configure do |c|
c.key = "###"
c.secret = "###"
c.tag = "###"
end
req << { :operation => 'ItemSearch',
:search_index => params[:product_type],
:response_group => %w{ItemAttributes Images},
:keywords => show.name,
:sort => "" }
resp = req.get
@items << resp.find('Item').shuffle.first
end
I did not notice that this action blocks the server. I tried to open the site in a different tab. This tab will not start loading until the first tab with an Ajax call completes.
How can I solve this problem?
Setup:
Ubuntu 10.10
Rails 3.1.1
Ruby 1.9.2
Gem: https://github.com/hakanensari/amazon_product
Frexuz source
share