What happens if you use the dataFilter function on jQuery.ajax? The docs say:<br><br><div>A function to be used to handle the raw response data of XMLHttpRequest.This is a pre-filtering function to sanitize the response. You should return the sanitized data. The function accepts two arguments: The raw data returned from the server and the 'dataType' parameter.</div>
<div><br></div><div>Just thinking you could decode the response in that function.</div><div><br></div><div>Never tried it though....</div><div><br></div><div>--Andrew<br><div><br><div class="gmail_quote">On Tue, Nov 15, 2011 at 12:42 PM, Joe Armstrong <span dir="ltr"><<a href="mailto:erlang@gmail.com">erlang@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">To anser my own question it's not so easy.<div><br></div><div>A bert encoded term starts <<131, ...>></div>
<div><br></div><div>Now 131 is not a single byte UTF8 character - when I make</div><div>an ajax call from jquery in the browser the ajax stuff tryoes to convert the blob containing a <<128,...>> to a utf8 string</div>
<div>and the decoding fails.</div><div><br></div><div>There are some html5 extensions -- something like</div><div><br></div><div><div> var r = new XMLHttpRequest();</div><div> r.open("GET", "get_bert", true); </div>
<div> r.responseType = "arraybuffer" </div><div> </div><div> r.onload = function(e) { // XHR2</div><div> var arr = new Uint8Array(this.response);</div></div><div><br></div><div>seems to work - but the exiting libraries cannot decode</div>
<div>a Unit8Array :-(</div><div><br></div><div>Why the heck sockets and ajax calls can't just sent back</div><div>sequences of bytes and not mess with them is a mystery to me</div><span class="HOEnZb"><font color="#888888"><div>
<br></div><div>/Joe</div></font></span><div class="HOEnZb"><div class="h5"><div><br>
<br><div class="gmail_quote">On Tue, Nov 15, 2011 at 2:56 PM, Joe Armstrong <span dir="ltr"><<a href="mailto:erlang@gmail.com" target="_blank">erlang@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>This looks good.</div><div><br></div>Another question.<div><br></div><div>Has anybody an example client-server example of bert?</div><div><br></div><div>I'm thinking:</div><div><br></div><div> server in erlang = bert + mochiweb/misultin/cowboy/yaws ...</div>
<div> client in browser = jquery + bert<br><br></div><div>Id like to make an ajax RPC from the client that returns a bert blob</div><div>unpacks the blob and displays the result.</div><div><br></div><font color="#888888"><div>
<br></div>
<div>/Joe</div></font><div><br><div class="gmail_quote"><div>On Tue, Nov 15, 2011 at 1:35 PM, Ulf Wiger <span dir="ltr"><<a href="mailto:ulf@feuerlabs.com" target="_blank">ulf@feuerlabs.com</a>></span> wrote:<br>
</div><div><div></div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
If you can settle for BERT, I think there are some JavaScript implementations out there:<br>
<br>
<a href="https://github.com/rtomayko/node-bertrpc/blob/master/src/bert.js" target="_blank">https://github.com/rtomayko/node-bertrpc/blob/master/src/bert.js</a><br>
<br>
BR,<br>
Ulf W<br>
<div><br>
On 15 Nov 2011, at 12:57, Joe Armstrong wrote:<br>
<br>
</div><div><div></div><div>> I'd like to send a term_to_binary encoded term to a web client and decode it in javascript.<br>
><br>
> If I could do this it would eliminate the impedance mismatch between server-side databases<br>
> and client code in a browser. I want to totally eliminate conversions to and from JSON. Just send<br>
> raw blobs containing term_to_binary encoded data and pluck what I want in the client.<br>
><br>
> I would not necessarily want to decode the entire blob, I might just want to extract a specific item<br>
> So for example if In Erlang I created a blob by saying<br>
><br>
> Blob = term_to_binary({thing,"foo","bar",["baz"]})<br>
><br>
> I'd like to send this to a browser and in Javascript say:<br>
><br>
> var z = mylib_hd(my_lib_element(4,Blob))<br>
><br>
> Whereby z would be the javascript string "baz".<br>
><br>
> Has anybody implemented anything like this?<br>
><br>
> /Joe<br>
><br>
><br>
><br>
</div></div><div><div></div><div>> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
</div></div></blockquote></div></div></div><br></div>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div></div>