I created some test code that uses Ajax to refresh/update two fields. It works great and now, to keep things neat, I have created a file called Ajax.js
In my HTML page where all my fields are, I would like to call this file and make it update the two variables.
I did the following:
In my HTML page:
<--- 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>
The call doesn't work, it doesn't update the fields. Here is the actual Ajax.js code:
// 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);
})
How can I call this properly? Hopefully, I explained myself correctly?
$(...).Ajax()?