views:

532

answers:

3

OKay, I'm a bit of a javascript n00b, so forgive me if this seems like an obvious question.

I want to write an application using processing-JS, and I'd like to be able to load it with server-side data. I haven't written the server side yet so I can use anything, but it seems the obvious AJAX thing would be to use JSON to upload the data into the page.

How can I get access to that data from my processing code? Is it something as easy as the data is in scope, or could be attached to the window object and directly accessed from the processing code?

Update: Let me refine the question a little bit. I'm comfortable with JSON (but thanks for the links) and with writing code for both the client and server; my real questino (which admittedly could be somewhat silly) is if I get data with, eg, JQuery, and want to manipulate it in processing-js, is it in the same name space? Do I have to do anything odd to access it?

+1  A: 

You could use jQuery like this to get JSON results from your server and iterate them to do whatever. I'm sure there wouldn't be a problem with using processing-JS and jQuery together.

cottsak
+1  A: 

Hello Charlie, i think you should visit www.json.org
There it explains how to use json both server-side and client-side from within a web-app.
Practically there should be many library implementations server-side that you can include in your web applications to transform your platform objects to json objects.
For sure there is an implementation that transforms java objects to JSON objects. To interpret client side data i think you can use another library that it should be on the same web site. The only problem is that i don't know if you can use javascript scripts into processing javascript to use javascript objects

M3rlino
+3  A: 

Your Processing code gets "sloppily" parsed and converted into JavaScript. Anything the parser doesn't understand just gets ignored, which means you can freely mix bits of JavaScript code in with your Processing and it will, in general, "just work".

Have a look here for more information: http://processingjs.org/reference/articles/best-pratice

j4mie