Javascript 如何在脚本上循环x次。(使用x的变量)

Javascript 如何在脚本上循环x次。(使用x的变量),javascript,json,loops,each,Javascript,Json,Loops,Each,我需要在脚本上循环某些时间: 脚本: var x = 3 $.get('{{ shop.domain }}/pageX.html?format=json', function (data) { //the actual script }); 我需要什么: var x = 3 $.get('{{ shop.domain }}/pageX.html?format=json', function (data) { //the actual script }); 我需要脚本对该脚本进

我需要在脚本上循环某些时间:

脚本:

var x = 3
$.get('{{ shop.domain }}/pageX.html?format=json', function (data) {
    //the actual script
});
我需要什么:

var x = 3
$.get('{{ shop.domain }}/pageX.html?format=json', function (data) {
    //the actual script
});
我需要脚本对该脚本进行3次检查:

第一次:

.get({shop.domain}}/page1.html?format=json',函数(数据){

第二次:

.get({shop.domain}}/page2.html?format=json',函数(数据){

第三次:

.get({shop.domain}}/page3.html?format=json',函数(数据){

但是,当x=4时,我需要将脚本检查4次

这可能吗?也许有一个


谢谢!

这样行吗

var x = 3;
for(i = 0; i < x; ++i) {
    $.get('{{ shop.domain }}/page' + i + '.html?format=json', function (data) {
        //the actual script
    });
}
var x=3;
对于(i=0;i
如果无法多次定义该函数:

function yourFunc(data) {
    // ...
}

var x = 3;
for(i = 0; i < x; ++i) {
    $.get('{{ shop.domain }}/page' + i + '.html?format=json', yourFunc);
}
函数yourFunc(数据){ // ... } var x=3; 对于(i=0;i
这样做会奏效吗

var x = 3;
for(i = 0; i < x; ++i) {
    $.get('{{ shop.domain }}/page' + i + '.html?format=json', function (data) {
        //the actual script
    });
}
var x=3;
对于(i=0;i
如果无法多次定义该函数:

function yourFunc(data) {
    // ...
}

var x = 3;
for(i = 0; i < x; ++i) {
    $.get('{{ shop.domain }}/page' + i + '.html?format=json', yourFunc);
}
函数yourFunc(数据){ // ... } var x=3; 对于(i=0;i
试试这样的方法

var x = 3
for(var i = 0; i <= x; i++){
    $.get('{{ shop.domain }}/page' + i + '.html?format=json', function (data) {
    //the actual script
    });
}
var x=3

对于(var i=0;i尝试这样的方法

var x = 3
for(var i = 0; i <= x; i++){
    $.get('{{ shop.domain }}/page' + i + '.html?format=json', function (data) {
    //the actual script
    });
}
var x=3

对于(var i=0;我不这么认为。我得到以下错误:不要在循环中生成函数。//actual脚本是一个包含函数的大脚本…:/我绝对不是JS专家,但是为什么不从
get()
中定义函数并将其传递给
get()
?我已经更新了我的答案。我不这么认为。我得到了以下错误:不要在循环中生成函数。//实际脚本是一个包含函数的大脚本…:/我绝对不是JS专家,但是为什么不从
get()
中定义函数并将其传递给
get())
?我已更新我的答案。这不起作用:(.我收到以下错误://实际脚本是一个包含函数的大脚本…:/这不起作用:(.我收到以下错误:不在循环中生成函数。//实际脚本是一个包含函数的大脚本…:/