views:

44

answers:

4

I'm considering creating a simple remote debugging application for Javascript. Actually, I want to provide an object to Firebug Lite and let it do all the job.

So, can I get an object from one page, serialize it, send it to server and then to another browser and finally see the same results in Firebug Lite (on that other client) as I would see on the first browser (with doing "console.dir(obj)")? Is it possible to do?

A: 

Using JSON for encoding the object?

http://json.org/

mhitza
A: 

The easiest solution is to serialize to JSON. However, it is important to note JSON does not support all JavaScript types.

Matthew Flaschen
A: 

Instead of just half-answering the question, here's the real deal!

Like the others said, use JSON (implementation details) to serialize your data (because it's nativly supported by Javascript and it's lightweight), and then send it to your server using AJAX, maybe by sending it to a PHP script that just saves it to a file or a database or something.

Then on the other side, you simply receive it by again using AJAX to ask said PHP script to return that data to you!

LukeN
+1  A: 

Plain answer: no. You'll have to serialize your object to some kind of string. It could be XML, or JSON, or a format you make up, like:

var anObject = {first:1,second:2,third:'infinite'};
function serializer(obj){
   var serialized = [];
   for (var l in obj){
     if (obj.hasOwnProperty(l)){
        serialized.push(l+'='+obj[l]);
     }
   }
   return serialized.join('&');
}

alert(serializer(anObject)); //=>first=1&second=2&third=infinite

If your object contains objects, you could use the serializer function recursively.

KooiInc