JavaScript Reload variables every 10 seconds

Okay here's the problem. I want to have 6 realtime variables in php (now they are like Divs). The method I use works fine but it's awful (I know). I need better solution.

Now I load 6 diffrent files like this:

<script>
function loadText() {
$.ajax({
    url: ("variable1.php"),
    cache: false,
    success: function(data) {
        $("#variable1").html(data);
    }
});
} setInterval(loadText, 60000);
</script>

<div id="variable1"></div>

What should I do? Thanks.

Answer:1

Are you going to want to do a setInterval()?

setInterval(function(){loadText();}, 10000);

Or, if you want it to run only after successfully completing the call, you can set it up in your .ajax().success() callback:

function loadText(){
    var text = $.ajax({
        type: "POST",
        url: "variable1.php",
        async: false
    }).success(function(){
        setTimeout(function(){loadText();}, 10000);
    }).responseText;

    $('#variable1').html(text);
}

Or use .ajax().complete() if you want it to run regardless of result:

function loadText(){
    var text = $.ajax({
        type: "POST",
        url: "variable1.php",
        async: false
    }).complete(function(){
        setTimeout(function(){loadText();}, 10000);
    }).responseText;

    $('#variable1').html(text);
}

Here is a demonstration of the two. Note, the success works only once because jsfiddle is returning a 404 error on the ajax call.

http://jsfiddle.net/YXMPn/

Answer:2

I am sure this one is staring me in the face. Trying to increase the rotation on an object until i reaches a value. Getting an error as I am trying to escape the CSS part to enter my variable 'i'. ...

I am sure this one is staring me in the face. Trying to increase the rotation on an object until i reaches a value. Getting an error as I am trying to escape the CSS part to enter my variable 'i'. ...

  1. escape characters enter

I have a owl carousel with 3 items, the carousel displays one item per page. Inside each item I have html inputs. I want to programmatically change the active item so I can make focus on input inside ...

I have a owl carousel with 3 items, the carousel displays one item per page. Inside each item I have html inputs. I want to programmatically change the active item so I can make focus on input inside ...

  1. get active item owl carousel
  2. owl carousel active item
  3. owl carousel center active item
  4. owl carousel active item bigger
  5. owl carousel first item active
  6. owl carousel set active item
  7. owl carousel active item css
  8. owl carousel 2 get active item
  9. owl carousel change active item
  10. owl carousel active item index
  11. owl carousel 2 active item
  12. owl carousel active item class
  13. owl carousel 2 set active item
  14. owl carousel active item left
  15. owl carousel get active item index
  16. owl carousel active item width
  17. owl carousel last active item
  18. owl carousel only one item active
  19. owl carousel find active item
  20. owl carousel 1 active item

Anyone managed to use ng-class for placing dynamic base64 encoded images as background-images for a div yet? Seems to work for JQuery (see Is there a way to set background-image as a base64 encoded ...

Anyone managed to use ng-class for placing dynamic base64 encoded images as background-images for a div yet? Seems to work for JQuery (see Is there a way to set background-image as a base64 encoded ...

  1. angularjs class dynamic
  2. angularjs dynamic class name
  3. angularjs dynamic class attribute
  4. angularjs dynamic class change
  5. angularjs ng-class dynamic
  6. add class angularjs dynamic
  7. angularjs set dynamic class
  8. angularjs ng-class dynamic class name

I am Implementing push notification in ionic using this tutorial: http://devdactic.com/ionic-push-notifications/ I have succesfully done using this. I got device token: like: Got token: DEV-...

I am Implementing push notification in ionic using this tutorial: http://devdactic.com/ionic-push-notifications/ I have succesfully done using this. I got device token: like: Got token: DEV-...