Ajax を使用して 2 つのフィールドを更新/更新するテスト コードをいくつか作成しました。それはうまく機能し、物事をきちんと保つために、Ajax.jsというファイルを作成しました
すべてのフィールドがある HTML ページで、このファイルを呼び出して、2 つの変数を更新させたいと思います。
私は次のことをしました:
私のHTMLページで:
<--- included the meta lines needed for the Ajax file ---->
<--- included: my jQuery includes needed ---------->
<---- my link to the Ajax.js file -------------->
<script src="Ajax.js"></script>
<----- made the call this way, I am not sure is right ------->
<!----- Ajax Update Fields Function ----->
<script>
jQuery('nav').Ajax();
</script>
呼び出しは機能せず、フィールドを更新しません。実際の Ajax.js コードは次のとおりです。
// JavaScript Document
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
$(function()
{
setInterval(function()
{
$.get("ajax_v00.html",function(data,textStatus, jqXHR)
{
var temperature=$(data).filter('#variable1').text()
var time=$(data).filter('#variable2').text()
$('#variable1').text(temperature)
$('#variable2').text(time)
})
.fail(function(jqxhr,textStatus,errorThrown) //Callback failed
{
$('#errors').text("Errors:" + textStatus + " " + errorThrown)
})
.done(function() //Callback succeeded
{
$('#errors').text('Errors:');
})
},1000);
})
どうすればこれを適切に呼び出すことができますか? うまくいけば、私は自分自身を正しく説明しましたか?