Forum Moderators: open

Message Too Old, No Replies

General question about JavaScript and AJAX

Getting variables with AJAX

         

TerryTom

8:44 pm on Sep 18, 2010 (gmt 0)

10+ Year Member



Hello all,
I've used AJAX, but am wondering whether it can be used for this:
A Javascript function which draws a shape using the HTML5 canvas tool, but getting the coordinates of the shape from an external document using AJAX.

Basically, can AJAX be used to dynamically import variables which can then be used by the rest of the Javascript code?

daveVk

12:43 am on Sep 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ajax can be used to retrieve data in any form. You could return the data as a CSV or XML and use a suitable parser to extract the data.

A more direct way is to return the data as JSON (subset of js) and eval() it to create javascript variables.

A bonus of using JSON is that the AJAX same origin can be avoided, allowing the data to from a 3rd party. The downside is that as you are not parsing the data, rouge JSON can do damage.