Route 9 Ruby Group Message Board › using JSON instead of AJAX

using JSON instead of AJAX

Sudbury, MA
Post #: 3
There was some mention of JSON at the meeting yesterday, which I didn't get a chance to follow up a bit more on, but I wasn't sure if people knew alot about or had an interest in what you can do with JSON ..

You can create stuff that behaves just like AJAX using a security hole in javascript, but one thing that it can do that you can't do in ajax is it can get an AJAX like widget from a different server. You can't do that in AJAX as that is cross site scripting and is not allowed. Using the JSON approach you can create web 2.0 widgets and put them on all kinds of different sites if you wanted to that are on different domains.

Here is sort of how we did it at work using PHP, though you could do the same thing in Rails just as easy:

<script> type="text/javascript" src="http://mywidgetserver...­ </script>

The PHP script here gets sourced as if it's javascript, and it returns a javascript object as well as whatever data you generate as JSON. You can convert RSS feeds or whatever into JSON. We actually had to write a bunch of javascript besides just the data part of it the way we did it.

There is also a Rails plugin that will replace prototype so that all the partial rendering stuff uses JSON instead of AJAX. I haven't used it a whole lot, but I did install it and got a simple example working without much effort.

Not sure if maybe people have heard of all that, but it was new to me until a few months ago.
Sudbury, MA
Post #: 4
Slight correction, the Rails pluggin I refered to used JQuery instead of prototype ..
Powered by mvnForum

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy