You don't describe the universe in which this needs to be unique.
If you mean absolutely unique, then you're talking about a UUID.
If you need something unique to the endpoint to prevent client-side caching, then this will suffice
var unique = new Date().getTime();
If you need something other than these two then you'll need to be more specific.
EDIT
Maybe something that looks a bit like this
jsonRpcClient = function()
{
var requestStack = [null];
this.makeRequest = function()
{
var id = this.getAvailableSlot();
requestStack[id] = new this.request( id, arguments );
}
this.getAvailableSlot: function ()
{
for ( var i = 0; i < requestStack.length: i++ )
{
if ( null == this.requestStack[i] )
{
return i;
}
}
return i;
}
this.request: function( id, args )
{
// request stuff here
// pass id and whatever else to jsonRpcClient.handleResponse()
}
this.handleResponse: function( id )
{
var request = requestStack[id];
requestStack[id] = null;
// Do whatever with request
}
};