oyvindkinsey / easyXDM

A javascript library providing cross-browser, cross-site messaging/method invocation.

Home Page:http://easyxdm.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No error if easyXDM.Rpc Remote URL does not exist

tysonnero opened this issue · comments

When creating a new easyXDM.Rpc object for cross-browser ajax in the below example, if the remote url defined does not exist, easyXDM does not throw an error when making a request but just dies without reporting anything.

var xhr = new easyXDM.Rpc({
    remote: "http://other.domain/cors/"
}, {
    remote: {
        request: {} // request is exposed by /cors/
    }
});

The use case for us is that our remote url is hosted by a service that may be down for some reason. We want a way to report if the remote url is down.

The only way to know if the iframe was successfully established is to listen on the onReady event. But it would be nice if the was an onError event as well although I'm not sure if even possible.

var xhr = new easyXDM.Rpc({
    remote: "http://other.domain/cors/",
    onReady: function () { alert('ready'); }
}, {
    remote: {
        request: {} // request is exposed by /cors/
    }
});

agree, very needed event!

ya, very needed when slow connection and remote can't be loaded

is possible to use a timeout that is clearerd after n ms if the onready isn't triggered.

var xhr;
var tm = setTimeout(function() {
   // code for not loaded iframe....
  // xhr.destroy() maybe
},30000);
xhr = new easyXDM.Rpc({
 new easyXDM.Rpc({
    remote: "http://other.domain/cors/",
    onReady: function () { 
       clearTimeout(tm); 
    }
}, {
    remote: {
        request: {} // request is exposed by /cors/
    }
});