We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How to access query results in JavaScript?

Development and Programming

geetika's avatar
geetika
19 posts
16 years ago
geetika's avatar geetika

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.

       
Brian M.'s avatar
Brian M.
529 posts
16 years ago
Brian M.'s avatar Brian M.

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 😉 )

It should look like:

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

Replace 5 with s.

       
Brian M.'s avatar
Brian M.
529 posts
16 years ago
Brian M.'s avatar Brian M.

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?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.