Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8775713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:52:27+00:00 2026-06-13T18:52:27+00:00

Using Magento, I need to pass values from the database to javascript in json

  • 0

Using Magento, I need to pass values from the database to javascript in json in a custom module. I am avoiding inline javascript due to CSP. I followed http://www.pierrefay.com/magento-create-block-44

I am having trouble with the type attribute for the block in the layout file. When I use page/html my javascript template file displays, but sends a text/html header instead of a text/javascript which I believe is a xss risk.

When I try a custom type, like auction/history, the javascript layout does not load. Instead it shows a blank page with the standard shop design. Below are my files

app/code/local/Mymodule/Auction/etc/config.xml

Here I have a custom product view page in the blocks in addition to the new block I am trying to use for the javascript.

<config>
...
  <frontend>
     <routers>
        <routeurfrontend>
            <use>standard</use>
            <args>
                <module>Mymodule_Auction</module>
                <frontName>auction</frontName>
            </args>
        </routeurfrontend>
     </routers>
     <layout>
       <updates>
            <auction>
                 <file>history.xml</file>
             </auction>
        </updates>
     </layout>
  </frontend> 

  <global>
    <blocks>
        <Mymodule_Auction>
            <class>Mymodule_Auction_Block_Catalog_Product_View</class>
        </Mymodule_Auction>
        <catalog>
            <rewrite>
                <product_view>Mymodule_Auction_Block_Catalog_Product_View</product_view>
            </rewrite>
        </catalog>
        <auction>
                <class>Mymodule_Auction_Block</class>
        </auction>
    </blocks>

     ... (code for models and helpers) ...

  </global>
</config>

app/design/frontend/Mymodule/default/layout/history.xml If I change the type=”auction/history” to “page/html” it displays but with text/html header instead of text/javascript

<layout version="0.1.0">
     <default>
          <reference name="content"></reference>
      </default>
    <auction_index_history>  
        <reference name="content">
            <block type="auction/history" template="auction/history.phtml" />
        </reference>
    </auction_index_history>  
</layout> 

app/code/local/Mymodule/Auction/Block/History.php

<?php
class Mymodule_Auction_Block_History extends Mage_Core_Block_Template
{
     public function methodblock()
     {
         return ‘informations about my block !!’ ;
     }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:52:28+00:00Added an answer on June 13, 2026 at 6:52 pm

    I think you’re mistaking Block and controllers.

    A block is only a part of your pages.
    A controller tells how your page should be rendered in the browser.

    About your question on the Block : when you need to create a new template without any related Block method, you should use core/template . This block is the top one (html/page inherits core/template but with added logic that you might not want)

    If you need some custom logic (Block methods), create a php Block class that inherits Mage_Core_Block_Template

    And about you’re header question : if you output only JSON, you should force the output of JSON using a controller and the method :

    $this->getResponse()->setHeader('Content-type', 'application/x-json');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create module in Magento which will have few database tables. One
I am using Magento for my online store. Now i need to add a
I am new to Magento and i am using Magento Ver. 1.6.1.0 - Custom
I am trying to call magento api using Soap from android but I am
I need your suggestions please, I'm currently using the Magento API for importing products
I've recently started using Magento for a client's webshop, and still need to get
I am using Magento ver1.6.1. I need to get the root category of a
I am developing a Ecommerce website by using version Magento 1.6. I need to
I have the need to pass a URL to Magento, where it should redirect
I have a custom model/object for a magento extension I'm working on. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.