我想展示一些通過Ajax加載的亞馬遜產品。Rails - 非阻塞HTTP請求?
我使用Ajax調用下面的方法,但請求需要幾秒鐘。
@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
我沒有看到這個操作阻止了服務器。我試圖讓該網站在另一個選項卡中打開。該選項卡不會開始加載,直到第一個帶有Ajax調用的選項卡完成。
我該如何解決這個問題?
設置:
的Ubuntu 10.10
的Rails 3.1.1
的Ruby 1.9.2
寶石:https://github.com/hakanensari/amazon_product
哦,這是有點令人失望:( – Frexuz