javascript - Calling Ajax periodically -


i calling java script function view page (mvc razor) initiates ajax call. want periodically re-occur. reason going in recursive loop

function getdata(url) {     $.ajax({         url: url,         type: "get",         contenttype: "application/json; charset=utf-8",         success: onsuccess,         error: onerror,         complete: function(xhr, status) {             settimeout(getdata(url), 5000);         }     }); }  function onsuccess(data, status, xhr) {     (var key in data) {         if (data.hasownproperty(key)) {             var id = data[key].id;             var value = data[key].value;             document.getelementbyid(id).innerhtml = value;         }     } } 

on html page side call function on page load

<script type="text/javascript">     getdata("someurl"); </script> 

any idea why going recursive when setting timeout in complete callback.

settimeout(getdata(url), 5000); calls getdata function , indeed goes infinite loop.

instead want pass function first argument:

settimeout(function() {   getdata(url); }, 5000); 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -