我有下面的代码时,它同步,我传递参数给它如何将参数传递给jquery异步json?
function getValues(itemid){
var parsedpage = $.ajax({
cache : false,
async : false,
url : "http://cors.io/?u=http://cata.openwow.com/item="+itemid,
dataType : "text",
});
return parsedpage.responseText;
}
getValues(70266);
getValues(70378);
getValues(70268);
有更多getValues
调用导致加载时间长和用户体验差,只有与Tampermonkey工作,想我应该重构它的工作同步,如果我将async:false
更改为async:true
该代码不适用于循环18个数字的循环。它必须以responseText
作为html代码这样做,因为网站并不真正支持json,或者我无法找到它,因为它根本没有记录。
如何重写我的函数以工作异步?我读过How do I return the response from an asynchronous call?但不包括通过我自己的函数参数
看起来像你需要一个'promise()' – Derek
jQuery''.when''就足够了吗? –
是的,它应该是 – Derek