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