RO SDK Javascript IE9 error

Testing this tutorial: http://wiki.remobjects.com/wiki/Calling_RemObjects_servers_from_Javascript_(Delphi),
it is working in Firefox, but I got : “object error” using IE9 when calling service method.
I tested using RoBinary message and the same error occurs.

I am using RO SDK 6.0.55.957 and Delphi 7.

Thanks
Willian.

First of all, that article is a bit outdated, please look at http://wiki.remobjects.com/wiki/Calling_RemObjects_SDK_Servers_from_JavaScript and http://wiki.remobjects.com/wiki/JavaScript_Platform in general.

I’d suggest to try Mega Demo JavaScript client first. It works in IE9 with JSONMessage. BinMessage isn’t supported in IE. Please tell if it works in your environment.

I tried this also (JSONMessage) and it worked with Firefox (like article’s screenshot) but no success with IE9 (same object error).

Just in case… Please try if your browser supports JSON.stringify/parse
Could be done with simple alert(JSON.stringify({A:1, B:2}))

Adding alert(JSON.stringify({A:1, B:2})) produces an error:
SCRIPT5009: ‘JSON’ não está definido (it is not defined)

When using IE8 compatibility, adding this line in my html :

alert(JSON.stringify({A:1, B:2})) is ok now (shows an alert {“A”:1,“B”:2})

But I got another error now (with IE8 compatibility):
Error: Error: AjaxWrapper.post: sendAsBinary is not defined, no data sent

I am little bit confused, the first article: http://wiki.remobjects.com/wiki/Calling_RemObjects_servers_from_Javascript_(Delphi) (outdated as you said) uses JSONMessage, but the other article that you recommended me http://wiki.remobjects.com/wiki/Calling_RemObjects_SDK_Servers_from_JavaScript uses binary message, that you told me not working in IE …

Which is the best solution to work with IE ?

Well, the best one seems not to use IE :slight_smile:
It doesn’t support posting binary data (haven’t researched IE10 yet) and sometimes it doesn’t support JSON.

So, the only solution in your case is to grab JSON implementation from https://github.com/douglascrockford/JSON-js and use JSONMessage

Thanks… any plan to add BinMessage support to IE ? IE has 50% browser market share …

JSONMessage will work on FPC/Linux ro-servers ?

I tested BinMessage with Firefox (fpc/linux) and it almost worked… just a problem with files having uppercase and lowercase together, example:

RemObjectSDK.js will be dispatched by the server if I rename it to remobjectssdk.js.

I’d love to, but its XMLHTTPRequest just doesn’t post binary data (treats it as a string and truncates at first zero byte)

Yes, JSONMessage should work.

Thanks for the filenames hint, we’ll check this.

I am testing with JSONMessage only.

If I write my own NewLibrary_intf.js (like this tutorial http://wiki.remobjects.com/wiki/Calling_RemObjects_servers_from_Javascript_(Delphi) ) everything works :slight_smile: … firefox, IE (with 8 compatibility) and FPC/Linux too.

But If I use generated NewLibrary_intf.js using RO Service Builder (CodeGen -> Javascript -> RO SDK for Javascript (.js) ) , nothing works :frowning: … I get empty result no matter what browser I am using (firefox, IE,etc).

I want to use generated intf file to save my work with a real service…

I attached a very simple test case reproducing my problem, what I am doing wrong?

Thanks,
Willian.

Please use generated version only. It is kept in sync with the library. As I said, that article is outdated and refers to beginning of RO/JS development. It’s probably time to redirect it to http://wiki.remobjects.com/wiki/Calling_RemObjects_SDK_Servers_from_JavaScript

The testcase seems to be fine. Please check if JSONMessage.WrapResult is true at the server side.

I’ve added a section to http://wiki.remobjects.com/wiki/Calling_RemObjects_SDK_Servers_from_JavaScript#Tips_.26_Tricks

Sorry for not doing this earlier.

I used that article because generated version not worked, but now is ok, JSONMessage.WrapResult := true worked … :slight_smile:

One detail, in FPC/Linux only works with I put RemObjectsSDK.js in my server html folder, not RemObjectsSDK.js but remobjectssdk.js (filename problem).

Like you said in another post (http://connect.remobjects.com/discussion/901/javascript) RemObjectsSDK.js is embedded into
ROJavaScriptHttpDispatcher component but in FPC is not working (I think due to this filename problems).

Hi,

Now I am testing RO DataAbstract JS with no success in IE:

msg.getErrorMessage() returns a empty message.

Chorme, Firefox OK. RO SDK in IE OK too.

Using JSON:

var Channel = new RemObjects.SDK.HTTPClientChannel(“http://localhost:8099/JSON”);
var Message = new RemObjects.SDK.JSONMessage();
var Service2 = new RemObjects.SDK.RemoteService(Channel, Message, “ScarabService”);
var Service3 = new RemObjects.SDK.RemoteService(Channel, Message, “LoginService”);
var daService = new DataAbstractService(Service2);
var Adapter = new RemObjects.DataAbstract.RemoteDataAdapter(Service2,Service3, RemObjects.DataAbstract.Bin2DataStreamer);
var aTable = new RemObjects.DataAbstract.DataTable(“SQL”);
var requestInfo = RemObjects.DataAbstract.Util.createRequestInfo()
Adapter.getData(aTable,requestInfo, isOK , function(msg) {
alert('ERRO = '+msg.getErrorMessage()) });

Thanks
Willian.

Hi,

Debugging… the error occurs here:

RemObjects.UTIL.fromBase64 = function(aValue) {
if (typeof(atob) != ‘undefined’) {
return atob(aValue.replace(/(\n|\r)+/g, “”));
} else {
throw(new Error(“Base64 decoding is not supported by your browser.”));
// return $.base64Decode(aValue);
};

};

Base64 decoding is not supported by your browser.

IE has no atoa/btob implementation.

I found this:

And changed DataAbstract.js source code:

RemObjects.UTIL.toBase64 = function(aValue) {
if (typeof(btoa) != ‘undefined’) {
return btoa(aValue);
} else {
return base64.encode(aValue);
//throw(new Error(“Base64 encoding is not supported by your browser.”));
//return $.base64Encode(aValue);
};
};

RemObjects.UTIL.fromBase64 = function(aValue) {
if (typeof(atob) != ‘undefined’) {
return atob(aValue.replace(/(\n|\r)+/g, “”));
} else {
return base64.decode(aValue.replace(/(\n|\r)+/g, “”));
//throw(new Error(“Base64 decoding is not supported by your browser.”));
// return $.base64Decode(aValue);
};

};

Is this ok? It is working for me now.

I’d use something more ‘unobtrusive’ like suggested in the library you’ve found:

  • if (!window.btoa) window.btoa = base64.encode
  • if (!window.atob) window.atob = base64.decode
I'd love to, but its XMLHTTPRequest just doesn't post binary data (treats it as a string and truncates at first zero byte)

I think that a simple solution to this problem would be to add an ‘EscapeZero’ option to the BinMessage class, or to create a new EscapedBinMessage class.
If enabled, on the server side every #0 char is replaced with i.e. #FF#F0, #FF is replaced with a double #FF#FF; the reverse is done on the client.
It’s a widespread solution for low-level serial communications.

that’d be incompatible with how the BinMessage protocol is defined, though; it would break every other client.

Couldn’t it be implemented as an Envelope then ?
Obvioulsy if you want IE9 compatibility you would have to add that Envelope to all of your clients, at least the ones connecting via HTTP (and implement the Envelope also in Javascript).
i.e. with two channels on the server side: one SuperTCP+BinMessage for “standard” clients, one HTTP+BinMessage+Envelope for Javascript ones, would it work at least in theory ?