How to access query results in JavaScript?
Posted: 26 August 2008 10:43 PM   [ Ignore ]  
Summer Student
Total Posts:  6
Joined  07-30-2008

Hi,

I have created a new module in EE and in mod.newmodule.php I am executing a query. After processing the query, the results create an array. I need to use this array in JavaScript of the template of the calling module.
How can I access this array created in mod.newmodule.php through the javascript of the template?

Please help.

Thanks.

Mod Edit: Moved to the Modules: Technical Assistance forum.

Profile
 
 
Posted: 28 August 2008 12:46 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  780
Joined  07-18-2006

First thought so it might not be the best way:

Could you just inline some javascript right in the body of the HTML?  So in your template it would look something like:

[removed]<!--
        var
x = {your_query_results_here};
        -->
[removed]";

Edit to add: Interesting - it took out the javascript declaration (guess that’s not safe HTML wink )

It should look like:

<5cript type="text/java5cript"><!--
        var
x = {your_query_results_here};
        --></
5cript>";

Replace 5 with s.

Profile
 
 
Posted: 28 August 2008 12:50 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  780
Joined  07-18-2006

Another option might be to set up a new template that only contains your SQL and outputs your javascript.  Then you could embed this template in the header?

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64912 Total Logged-in Users: 21
Total Topics: 81863 Total Anonymous Users: 18
Total Replies: 440100 Total Guests: 188
Total Posts: 521963    
Members ( View Memberlist )
Newest Members:  bjmohrAqua193Bios Elementmjpoteetguimogranwelshmrcfthenetmonkeybenekwhobutsb