I have a JS that sends a request to a PHP script:
Code:
getBlog(alias,numPosts);
The PHP script will create a custom object called $blog, and call the SQL database to get the last posts of the blog.
The blog posts will then be added to the $blog object which will be json encoded and returned to the JS:
Code:
echo 'handleResponse('.json_encode($blog).');';
Back in the JS I eval the object and then I have to loop through it and create its JS counterpart.
This is done because the blog object in JS has some member functions I wanna be able to use (like creating styleable DOM nodes filled with member strings).
One of the problems with this is that whenever I remodel the $blog object I must remember to remodel its JS counterpart.
I was thinking that maybe I should only create the object in PHP and then loop through it and echo it as a string.
The string would be formatted for javascript syntaxing.
Then I could use that document as a script src and thus retrieve the JS object definition automatically.
That way I would only have to keep track of the PHP object and of course the SQL.
Have I missed something that would be of use in this situation to more
easily have an object flow from SQL through PHP to JS and back?
Ideally I would want a custom object that only contains the member variables and values (JSON object).
That object would then be equipped with member functions to do DOM stuff when it is in JS,
and it could be equipped with funtions to do SQL stuff when in PHP.
__________________
You couldn't fool anyone on the foolingest day of your life even if you had an electrical fooling machine!
|