Two ways to improve your survey are described below:
1) More effective AJAX polling
, ajax ( , ), , . $.ajax() complete. timeout (.. 30 ) , , , - .
(function betterPoll(){
$.ajax({ url: 'http://music.wickedradionet.com/api/live-info/', success: function (data) {
}, dataType: "json", complete: betterPoll, timeout: 30000 });
})();
2) WebSocket
WebSocket. , " ".
Node.js, docs , Socket.IO WebSocket. PHP, Ratchet PHP WebSockets.
Socket.IO:
HTML:
<script src="https://cdn.socket.io/socket.io-1.3.5.js"></script>
<script src="example.js"></script>
"example.js" - :
var socket = io.connect('http://music.wickedradionet.com/api/live-info/');
socket.on('an event', function (data) {
socket.emit('another event', { other: 'data' });
});
- .on('another event', function () {}) .emit('an event', function () {}).