<分区>
我有以下功能,但未能成功尝试在每次请求 2 秒后添加暂停以不超过 RPM 阈值。
<cfoutput>
<script type="text/javascript" language="JavaScript">
// Convert ColdFusion variable to JS variable
#ToScript(Variables.resourceIds, "jsList")#
// Split list
var list = jsList.split(",");
// Loop through list
for (var i=0; i<list.length; i++) {
var pricingSearch = new XMLHttpRequest();
pricingSearch.open("GET", "doPricing.cfm?ID=" + list[i], false);
pricingSearch.onload = function (e) { };
pricingSearch.onerror = function (e) { };
pricingSearch.send(null);
console.log('Searching for Id ' + list[i] + '...');
setTimeout(function() {
// Wait for a couple seconds
}, 2000);
if (i == list.length) {
console.log('All done!');
}
}
</script>
</cfoutput>
这似乎没有做任何事情,因为循环尽可能快地完成。
我什至尝试过修改代码:
for (var i=0; i<list.length; i++) {
setTimeout(function(list,i) {
var pricingSearch = new XMLHttpRequest();
pricingSearch.open("GET", "doPricing.cfm?ID=" + list[i], false);
pricingSearch.onload = function (e) { };
pricingSearch.onerror = function (e) { };
pricingSearch.send(null);
console.log('Searching for Resource Id ' + list[i] + '...');
if (i == list.length) {
console.log('All done!');
}
}, 2000);
}
但这也行不通:(
还有其他人知道我可以使用任何其他方法来实现这一目标吗?
谢谢