在AJAX请求的回调函数中动态加载Jquery。例如:
function loadData(data) {
// 处理数据
// ...
// 动态加载Jquery
if (typeof jQuery === 'undefined') {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://code.jquery.com/jquery-3.5.1.min.js";
document.head.appendChild(script);
}
}
for (var i = 0; i < 10; i++) {
$.ajax({
url: "https://example.com/api/data",
success: loadData
});
}
上述代码会在每次AJAX请求返回成功时调用loadData函数,并在其中加载Jquery。如果已经加载过Jquery,则不会再次加载。这样可以避免在AJAX循环中重复加载Jquery的问题。