Сложно сказать точно, чего вы хотите от вопроса, но вы ищете что-то подобное?
// Declare variables
var timedUpdate, getRequestParams, url, updateTimeout;
// Define timedUpdate function
timedUpdate = function () {
// Declare variables
var xmlHttp, params;
// Create a new AJAX object
xmlHttp = new XMLHttpRequest();
// Define a call back function
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState < 4) {
return; // Only do something if the request if complete
}
if (xmlHttp.responseCode != 200) {
// Handle HTTP errors here
// e.g.
alert('Something went wrong with the AJAX request (HTTP '+xmlHttp.responseCode+')');
}
// Do your thing with the returned data
// Set the function to run again after updateTimeout seconds
setTimeout(timedUpdate, updateTimeout * 1000);
};
// Get the request parameters
params = getRequestParams();
// Send the request
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.send(params);
};
// Define getRequestParams function
getRequestParams = function () {
// This function returns a parameter string to be used in the request
// I am guessing you need to generate a new one every 10 minutes
return "lorem=ipsum&name=binny";
};
// Define the URL to be used in the requests
url = "http://localhost/";
// Define how often the function is repeated, in seconds
updateTimeout = 600; // 10 minutes
// Make the first call to the function
timedUpdate();