Reply
JS and PHP both refer to the same object
Old 02-27-2009, 11:28 AM JS and PHP both refer to the same object
Novice Talker

Posts: 10
Name: Anders
Location: Sweden
Trades: 0
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!
Svartgam is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Reply     « Reply to JS and PHP both refer to the same object
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.09272 seconds with 13 queries