Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用按钮创建的函数轮询_Javascript_Jquery - Fatal编程技术网

Javascript 使用按钮创建的函数轮询

Javascript 使用按钮创建的函数轮询,javascript,jquery,Javascript,Jquery,我已经编写了一个jQuery脚本。正如我所想,这应该从JSON中获取templateTotal(USB上存在的模板总数)的数量,并根据templateTotal指示生成尽可能多的按钮 例如,如果templateTotal为6,则脚本应生成6个按钮 (function poll() { setTimeout(function () { $.ajax({ type: "GET", url: "/api/status",

我已经编写了一个jQuery脚本。正如我所想,这应该从JSON中获取
templateTotal
(USB上存在的模板总数)的数量,并根据
templateTotal
指示生成尽可能多的按钮

例如,如果
templateTotal
为6,则脚本应生成6个按钮

(function poll() {
    setTimeout(function () {
        $.ajax({
            type: "GET",
            url: "/api/status",
            processData: true,
            dataType: 'text',
            cache: false,
            success: function (data, textStatus, request) {
                var template = jQuery.parseJSON(data);
                var templateButton = "";
                for (i = 1; i > templateTotal; i++);
                templateButton +=  '<button class="templateButton" id="T' + i + '" formaction="/api/template" post="template=' + i + '">T' + i + '</button>'
            },
            complete: poll
        });
    });
})();
(函数轮询(){
setTimeout(函数(){
$.ajax({
键入:“获取”,
url:“/api/status”,
processData:对,
数据类型:“文本”,
cache:false,
成功:功能(数据、文本状态、请求){
var template=jQuery.parseJSON(数据);
var templateButton=“”;
对于(i=1;i>templateTotal;i++);
templateButton+='T'+i+'
},
完成:投票
});
});
})();

在for循环的
后面有一个分号:

 for(i=1; i > templateTotal; i++);
应该是:

 for(i=1; i > templateTotal; i++)
                templateButton += '<button class="templateButton" id="T' 
               + i     +'"
               formaction="/api/template"post="template='+i+'">T'+i+'</button>'
for(i=1;i>templateTotal;i++)
templateButton+='T'+i+'

for(i=1;i>templateTotal;i++){
templateButton+=
‘T’+i+’
}
分号表示语句的结尾(回车也是如此)。for循环(除非后面有括号)将执行分号结尾的下一条语句


分号不是结束语句所必需的,但最好是将其放进去。省略它仍将创建有效的语法。

for
循环后有一个分号:

 for(i=1; i > templateTotal; i++);
应该是:

 for(i=1; i > templateTotal; i++)
                templateButton += '<button class="templateButton" id="T' 
               + i     +'"
               formaction="/api/template"post="template='+i+'">T'+i+'</button>'
for(i=1;i>templateTotal;i++)
templateButton+='T'+i+'

for(i=1;i>templateTotal;i++){
templateButton+=
‘T’+i+’
}
分号表示语句的结尾(回车也是如此)。for循环(除非后面有括号)将执行分号结尾的下一条语句


分号不是结束语句所必需的,但最好是将其放进去。省略它仍将创建有效的语法。

for
循环后有一个分号:

 for(i=1; i > templateTotal; i++);
应该是:

 for(i=1; i > templateTotal; i++)
                templateButton += '<button class="templateButton" id="T' 
               + i     +'"
               formaction="/api/template"post="template='+i+'">T'+i+'</button>'
for(i=1;i>templateTotal;i++)
templateButton+='T'+i+'

for(i=1;i>templateTotal;i++){
templateButton+=
‘T’+i+’
}
分号表示语句的结尾(回车也是如此)。for循环(除非后面有括号)将执行分号结尾的下一条语句


分号不是结束语句所必需的,但最好是将其放进去。省略它仍将创建有效的语法。

for
循环后有一个分号:

 for(i=1; i > templateTotal; i++);
应该是:

 for(i=1; i > templateTotal; i++)
                templateButton += '<button class="templateButton" id="T' 
               + i     +'"
               formaction="/api/template"post="template='+i+'">T'+i+'</button>'
for(i=1;i>templateTotal;i++)
templateButton+='T'+i+'

for(i=1;i>templateTotal;i++){
templateButton+=
‘T’+i+’
}
分号表示语句的结尾(回车也是如此)。for循环(除非后面有括号)将执行分号结尾的下一条语句


分号不是结束语句所必需的,但最好是将其放进去。省略它仍将创建有效的语法。

您的代码有2个错误

1)
后面的分号表示

循环的平均值将被执行templateTotal次,而不执行任何操作。然后

  templateButton += '<button class="templateButton" id="T' + i +'" formaction="/api/template" post="template='+i+'">T'+i+'</button>'
templateButton+='T'+i+'
此代码只运行一次。请删除分号

2) 还有代码

  templateButton += '<button class="templateButton" id="T' + i +'" formaction="/api/template" post="template='+i+'">T'+i+'</button>'
templateButton+='T'+i+'

缺少
分号。

您的代码有2个错误

1)
后面的分号表示

循环的平均值将被执行templateTotal次,而不执行任何操作。然后

  templateButton += '<button class="templateButton" id="T' + i +'" formaction="/api/template" post="template='+i+'">T'+i+'</button>'
templateButton+='T'+i+'
此代码只运行一次。请删除分号

2) 还有代码

  templateButton += '<button class="templateButton" id="T' + i +'" formaction="/api/template" post="template='+i+'">T'+i+'</button>'
templateButton+='T'+i+'

缺少
分号。

您的代码有2个错误

1)
后面的分号表示

循环的平均值将被执行templateTotal次,而不执行任何操作。然后

  templateButton += '<button class="templateButton" id="T' + i +'" formaction="/api/template" post="template='+i+'">T'+i+'</button>'
templateButton+='T'+i+'
此代码只运行一次。请删除分号

2) 还有代码

  templateButton += '<button class="templateButton" id="T' + i +'" formaction="/api/template" post="template='+i+'">T'+i+'</button>'
templateButton+='T'+i+'

缺少
分号。

您的代码有2个错误

1)
后面的分号表示

循环的平均值将被执行templateTotal次,而不执行任何操作。然后

  templateButton += '<button class="templateButton" id="T' + i +'" formaction="/api/template" post="template='+i+'">T'+i+'</button>'
templateButton+='T'+i+'
此代码只运行一次。请删除分号

2) 还有代码

  templateButton += '<button class="templateButton" id="T' + i +'" formaction="/api/template" post="template='+i+'">T'+i+'</button>'
templateButton+='T'+i+'

缺少
分号。

请告诉我wat是isse?请告诉我wat是isse?请告诉我wat是isse?请告诉我wat是isse?@user234110您刚刚创建了一个字符串,您忘了附加它
。append(templateButton)
html(templateButton)
它会出现在哪里?sry。。。我是一个新手)这会让你从正确的方向开始:现在你已经创建了HTML,你必须将它附加到页面中的DOM中。@user234110你只是在创建一个字符串,你忘记了附加它
。append(templateButton)
。HTML(templateButton)
,它会出现在哪里?sry。。。我是一个新手)这会让你从正确的方向开始:现在你已经创建了HTML,你必须将它附加到页面中的DOM中。@user234110你只是在创建一个字符串,你忘记了附加它
。append(templateButton)
。HTML(templateButton)
,它会出现在哪里?sry。。。我是一个新手)这会让你从正确的方向开始:现在你已经创建了HTML,你必须将它附加到页面中的DOM中。@user234110你只是在创建一个字符串,你忘记了附加它
。append(templateButton)
。HTML(templateButton)
,它会出现在哪里?sry。。。