CodeIgniter Forums
AJAX, DOM and PHP - passing data around - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: AJAX, DOM and PHP - passing data around (/showthread.php?tid=2620)



AJAX, DOM and PHP - passing data around - El Forum - 08-15-2007

[eluser]obiron2[/eluser]
I am tyring to build a web 2.0 site as proof of concept.

I have found a useful Javascript function that will take a PHP serialized object and convert it intoa Javascript object so that I can play around with it and drop properties into the DOM without messing with XML.

There are also functions available to serialise a Js object.

Lets say that I have a form on screen (i.e. in the DOM) with an indeterminate number of lines in it (lets say that it is a shopping basket order) and I want to be able to dynamically modify form values (e.g. You increase the qty on a line and you now qualify for a discount). Using traditional SUBMIT of the form will force the page to refesh.

What I want to do is every time the user exits a field in the form, submit ALL the form data to PHP so that it can be captured into the database (MySQL), have PHP return the form data as an object (serialised), unserialise it and replace the form with the new data. (speed and environment settings are not necesarily an issue here)

serialising the form object in Js is not an issue, but I don't think I can pass that straight to the ajax call because I don't know how many parameters there will be and the serialised data may contain illegal characters (quotes, slashes, curly braces etc).

I was thinking about taking the serialised data string and encrypting it client-side and then using the encrypted string as a single parameter ('coz it now contains all the object data) and then decrypting it when I get it back to CI so that I can use object notation for the SQL update.


Has anyone ever done this, or can you see any drawbacks - the two I can forsee are speed and then length of the URL.

TIA

Obiron


AJAX, DOM and PHP - passing data around - El Forum - 08-15-2007

[eluser]Drinian[/eluser]
This may or may not help. The extjs library deals with this kind of thing with its javascript components, like the grid component. They use JSON data to communicate back and forth with PHP. PHP 5 has built in JSON encoding and decoding functions. If you're using a version lower than PHP 5 then you can use a PEAR class to do the encoding/decoding.

There are some links on this page that talk about it for the extjs.


Extjs tutorial page

Hope that helps.