Skip to content

Instantly share code, notes, and snippets.

@zclancy
Created February 9, 2012 18:18
Show Gist options
  • Save zclancy/1781761 to your computer and use it in GitHub Desktop.
Save zclancy/1781761 to your computer and use it in GitHub Desktop.
Updated sametime_invoke using jQuery/AJAX/callback functions
var Instant = {};
Instant.launchSametimeConversation = function (stid) {
var time = new Date();
var getUrl = 'http://localhost:59449/stwebapi/chat?userId=' + stid + '&time=' + time.getTime() + '&jsonp=Instant.handleResponse';
// Use jQuery to request the Sametime servlet URL. If a request makes it to the URL successfully, the servlet will return a code 200 and open the Sametime client chat with the user.
// We use the Instant.handleResponse() function as a callback to process the JSONP data object that the servlet hands back.
$.ajax({
type: 'GET',
url: getUrl,
dataType: 'jsonp',
jsonpCallback: 'Instant.handleResponse'
});
};
// A rudimentary callback function to handle JSONP data objects retrieved by the Instant.launchSametimeConversation() function.
Instant.handleResponse = function (data) {
if (data.returnCode === 200) {
alert('Success!');
} else {
alert('Failed!');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment