0
这里是我的例子我在Input.html文件中有两个变量,我需要每秒检索一次变量并将值分配到index.html文件的文本框中,帮助我在那里我做了错误.. 我试图左右逢源..json自动刷新和检索结果
<!--or can I use this script-->
<script type="text/javascript">
$(document).ready(function(){
$.ajaxSetup({ cache: false });
setInterval(function() {
$.getJSON("input.html", function (data) {
if (data.var1 == true) {
$('#Cycle1').val(result.trim());
}
if (data.var2 == true) {
$('#Cycle2').val(result.trim());
}
});
}, 1000);
});
</script>
<!--input.html-->
{
"var1":"1"
"var2":"2"
}
<!--end of input.html-->
<!-- index.html-->
<html>
<head>
</head>
<body>
<input type="text" id="Cycle1">
<input type="text" id="Cycle2">
</body>
<script type="text/javascript">
setInterval(function() {
$.getJSON("input.html", function (data) {
if (data.var1 == true) {
document.getElementById('Cycle1').value = var1;
}
if (data.var2 == true) {
document.getElementById('Cycle2').value = var2;
}
});
}, 1000);
</html>
'代码<脚本类型= “文/ JavaScript的”> 的$(document)。 ready(function(){.ajaxSetup({cache:false}); setInterval(function(){ $ .get(“Input.html”,function(result){ $('#counter'))。 text(result.trim()); }); },1000); }); '此代码已成功运行index.html中的标签,并且Input.html文件只有一个字母可以动态增加,我试图在Input.html中对多个输入做同样的事情,同时设置值在文本框而不是标签input.html – RJ10
我已经更新了我的例子,并包括一个[演示](http://jsfiddle.net/shccy08y/)它的工作:) – Sean3z
我应用你的逻辑在我的模块它是在小提琴中工作得很好,但同样的事情在浏览器中不起作用,我无法理解这个问题。 [小提琴](http://jsfiddle.net/1mmwfy9q/)我的例子文件。你能找出问题所在吗? – RJ10