我有一個用Ruby編寫的API代碼,它在循環中的請求中調用API,因爲我們最多可以得到50個結果。但我想在jQuery中創建這個API請求。我不知道我將如何做到這一點。如何在jQuery中獲取和發佈API請求?
這裏是我的Ruby代碼:
totalsequence = []
start = 0
begin
response = HTTParty.get("https://api.ontraport.com/1/objects?objectID=5&start=" + start.to_s,
{
:headers => { 'Api-Appid' => '', 'Api-Key' => ''}
})
totalsequence = totalsequence + response['data']
start += 50
end until (response['data']).size == 0
render json: JSON.pretty_generate(totalsequence)
所以我想這個代碼轉換爲jQuery的。
我不是你問清楚了嗎? – MZaragoza
如果只是將上面的代碼轉換爲jQuery,快速谷歌搜索會導致大量代碼示例。 – Sid
[jQuery Ajax簡單調用]的可能重複(http://stackoverflow.com/questions/19015897/jquery-ajax-simple-call) –