I have a web page that communicates with a node.js backend. I use AJAX to long-poll the server, allowing realtime updates to be received as they occur server-side.
Below is a simplification of my existing client-side code. What I'd like to know is whether there's an equivalent way of doing this with Visualforce/Apex, or can I even host my existing code somehow within an apex page? Any hints, examples or walkthroughs would be more than welcome – I have only been using the Force platform for 3 days so I am still extremely unfamiliar with the technology, terminology, etc.
Also, the data I'm polling for is not Salesforce related, so I don't think the Streaming API will work because the whole topic/query concept is not applicable in this situation.
function poll() {
longPollRequest = $.ajax({
url: "http://myserver.com/longPoll",
type: "GET",
dataType: "jsonp",
jsonpCallback: "localJsonpCallback",
complete: function(jqXHR, textStatus ) {
poll(); // restart the poll
},
error: function (jqXHR, textStatus, errorThrown) { }
});
}
function localJsonpCallback(json) {
// parse long-poll response
}
Best Answer
Take a look at the Streaming API. You can have your VF page subscribe to a topic and get near real time updates. This blog post does a really good job walking you through setting it up on your page.