Imam 4 razlicita php fajla, koji kad se pokrenu daju 4 razlicite vrednosti. Njih pozivaju javascript funkcije svake 2 sekunde. Medjutim, posto imam 4 ili 5 php fajlova, svi oni komuniciraju sa drugim sajtom da prigrabe vrednost. Pokusao bih da smanjim opterecenje na serveru i da sve te php kodove smestim u jedan fajl i jednom da se obraca serveru. To znam kako da odradim, ali ne znam kako ove jquery funkcije da smestim u jednu:
Kako bi vi ove dve funkcije smestili u jednu?
Code:
$(document).ready(function() {
setInterval('USDBTC()',2000);
setInterval('RSDEUR()',2000);
setInterval('USDEUR()',2000);
setInterval('USDXAU()',2000);
});
function USDBTC() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById('usdbtc').innerHTML = this.responseText;
}
};
xhttp.open('GET', '<?php echo ROOT; ?>scripts/usdbtc.php', true);
xhttp.send();
}
function RSDEUR() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById('rsdeur').innerHTML = this.responseText;
}
};
xhttp.open('GET', '<?php echo ROOT; ?>scripts/rsdeur.php', true);
xhttp.send();
}
itd...
$(document).ready(function() {
setInterval('USDBTC()',2000);
setInterval('RSDEUR()',2000);
setInterval('USDEUR()',2000);
setInterval('USDXAU()',2000);
});
function USDBTC() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById('usdbtc').innerHTML = this.responseText;
}
};
xhttp.open('GET', '<?php echo ROOT; ?>scripts/usdbtc.php', true);
xhttp.send();
}
function RSDEUR() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById('rsdeur').innerHTML = this.responseText;
}
};
xhttp.open('GET', '<?php echo ROOT; ?>scripts/rsdeur.php', true);
xhttp.send();
}
itd...
Kako bi vi ove dve funkcije smestili u jednu?