magento ajax not working on frontend - ajax

I created a block path is : local\Attribute\Layout\Controllers\ProductController code is
class Attribute_Layout_ProductController extends Mage_Core_Controller_Front_Action
{
public function ajaxDataAction()
{
echo 'ajax controller';
}
}
And in etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Attribute_Layout>
<version>0.0.1</version>
</Attribute_Layout>
</modules>
<global>
<blocks>
<attribute_layout>
<class>Attribute_Layout_Block</class>
</attribute_layout>
</blocks>
</global>
<frontend>
<routers>
<layout>
<use>standard</use>
<args>
<module>Attribute_Layout</module>
<frontName>layout</frontName>
</args>
</layout>
</routers>
<layout>
<updates>
<attribute_layout module="Attribute_Layout">
<file>attribute_layout.xml</file>
</attribute_layout>
</updates>
</layout>
</frontend>
</config>
And design\frontend\default\shirt_cust\layout\attribute_layout.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout version="1.0">
<default>
<attribute_layout_product_ajaxData>
<block type="layout/product" name="root" output="toHtml" template="attribute_layout/product.phtml" />
</attribute_layout_product_ajaxData>
</default>
</layout>
And ajax template in design\frontend\default\shirt_cust\template\product.phtml
$.ajax({
url:'<?php echo $this->getUrl('layout/product/ajaxData') ?>',
type:'post',
data: {id:31},
success:function(result) {
$('#res_html').html(result);
}
});
My ajax url in local localhost/shirt/layout/product/ajaxData is working fine
but not working in my server. path is: 162.144.13.7/o/tailorcustmize/layout/product/ajaxData
Getting 404 error
I tried anything but didn't find any solution please help me to solve this problem
What is the problem in this code please suggest anything. My server is linux.

etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Attribute_Layout>
<version>0.0.1</version>
</Attribute_Layout>
</modules>
<frontend>
<routers>
<layout>
<use>standard</use>
<args>
<module>Attribute_Layout</module>
<frontName>layout</frontName>
</args>
</layout>
</routers>
<layout>
<updates>
<layout>
<file>attribute_layout.xml</file>
</layout>
</updates>
</layout>
</frontend>
<global>
<blocks>
<layout>
<class>Attribute_Layout_Block</class>
</layout>
</blocks>
</global>
</config>
And design\frontend\default\shirt_cust\layout\attribute_layout.xml
<?xml version="1.0"?>
<layout version="0.0.1">
<layout_product_ajaxData>
<block type="layout/product" name="root" output="toHtml" template="attribute_layout/product.phtml" />
</layout_product_ajaxData>
</layout>

Related

Magento 1.9 add layout and template to custom module in admin

I try to create custom module that shows on main page two tabs with option to change titles, backgrounds, colors.
I successfully add the module tab in admin and can't add layout and template.
I'm stuck.
Can any one explain, please, how I can do this?
Here are the xml files that I got:
config.xml
<?xml version="1.0"?>
<config>
<modules>
<Lern_Sample>
<version>0.1.0</version>
</Lern_Sample>
</modules>
<frontend>
<routers>
<sample>
<use>standard</use>
<args>
<module>Lern_Sample</module>
<frontName>sample</frontName>
</args>
</sample>
</routers>
</frontend>
<admin>
<routers>
<sample>
<use>admin</use>
<args>
<module>Lern_Sample</module>
<frontName>admin_sample</frontName>
</args>
</sample>
</routers>
</admin>
<global>
<helpers>
<sample>
<class>Lern_Sample_Helper</class>
</sample>
</helpers>
</global>
<adminhtml>
<menu>
<sample module="sample">
<title>Sample Module</title>
<sort_order>100</sort_order>
<children>
<sample module="sample">
<title>Sample Module</title>
<sort_order>0</sort_order>
<action>admin_sample/adminhtml_index</action>
<layout>
<lern_sample>
<file>lern_sample.xml</file>
</lern_sample>
</layout>
</sample>
</children>
</sample>
</menu>
</adminhtml>
module xml etc/Lern_Sample.xml
<?xml version="1.0"?>
<config>
<modules>
<Lern_Sample>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Adminhtml />
</depends>
</Lern_Sample>
</modules>
You can add your own layout file by declaring it under the node <frontend>, just like this :
<layout>
<updates>
<sample>
<file>sample.xml</file>
</sample>
</updates>
</layout>
Your layout file will have to be located under app/design/frontend/MY_CUSTOM_PACKAGE/MY_DEFAULT_THEME/layout/sample.xml or under the base installation app/design/frontend/base/default/layout/sample.xml
If you try to add a layout update file for the admin, just use this code sample under the node <adminhtml>.

Magento: loading frontent layout

I have a module in app/code/community/Foo/Bar/. Now, I wrote most of it, but I have a problem adding a into head on every page. My config.xml:
<?xml version="1.0"?>
<config>
<modules>
<FooBar_BrowserSearch>
<version>0.1.0</version>
</FooBar_BrowserSearch>
</modules>
<global>
<helpers>
<browsersearch>
<class>FooBar_BrowserSearch_Helper</class>
</browsersearch>
</helpers>
</global>
<frontend>
<layout>
<updates>
<mmbrowsersearch>
<file>browsersearch.xml</file>
</mmbrowsersearch>
</updates>
</layout>
</frontend>
<default>
<bs_general>
<bs_general_settings>
<bs_shortname>My Store Search</bs_shortname>
<bs_description>My default search plugin description</bs_description>
<bs_contact>admin#mysite.com</bs_contact>
</bs_general_settings>
</bs_general>
</default>
</config>
then, I've created /app/design/frontend/base/default/layout/browsersearch.xml, like so:
<layout version="0.1.0">
<browsersearch>
<reference name="head">
<action method="addLinkRel">
<rel>search</rel>
<href>myfile.xml</href>
</action>
</reference>
</browsersearch>
</layout>
but the
I've just changed <browsersearch> into <default>, and it works.

how call custom module block in template file using layout configration file in magento

friends
i have created custom module ,in which i have crated blocks .i want use this block in template but this is not work.
This is my config file :-
<?xml version="1.0"?>
<config>
<modules>
<CustomModule_SocialLogin>
<version>1.0.0</version>
</CustomModule_SocialLogin>
</modules>
<frontend>
<routers>
<customer>
<args>
<modules>
<CustomModule_SocialLogin before="Mage_Customer">CustomModule_SocialLogin_Customer </CustomModule_SocialLogin>
</modules>
</args>
</customer>
<sociallogin>
<use>standard</use>
<args>
<module>CustomModule_SocialLogin</module>
<frontName>sociallogin</frontName>
</args>
</sociallogin>
</routers>
<layout>
<updates>
<CustomModule_SocialLogin module="CustomModule_SocialLogin">
<file>CustomModule/sociallogin.xml</file>
</CustomModule_SocialLogin>
</updates>
</layout>
</frontend>
<global>
<blocks>
<CustomModule_SocialLogin>
<class>CustomModule_SocialLogin_Block</class>
</CustomModule_SocialLogin>
</blocks>
<models>
<CustomModule_SocialLogin>
<class>CustomModule_SocialLogin_Model</class>
</CustomModule_SocialLogin>
</models>
<helpers>
<CustomModule_SocialLogin>
<class>CustomModule_SocialLogin_Helper</class>
</CustomModule_SocialLogin>
</helpers>
</global>
</config>
My block file -:
class CustomModule_SocialLogin_Block_Qa extends Mage_Core_Block_Template{
public function getText()
{
$name='test';
return $name;
}
}
custom module layout update file :-
<layout version="0.1.0">
<default>
<reference name="content" translate="label">
<block type="custommodule_sociallogin/qa" name="SocialLogin.qa" template="CustomModule/SocialLogin/questionans.phtml" />
</reference>
</default>
</layout>
my template file :-
<?php
echo $this->getText()->toHtml();
//echo $this->getText();
?>
Please help me to solve this error .
You need to correct your module layout file. I have corrected the block type.
<layout version="0.1.0">
<default>
<reference name="content" translate="label">
<block type="sociallogin/qa" name="SocialLogin.qa" template="CustomModule/SocialLogin/questionans.phtml" />
</reference>
</default>
In template file :-
<?php
echo $this->getText();
?>

Magento not able to assign Rewrite Reports Product Viewed block

I just need to create recent Product View Slider.
So i want to overide Reports_Product_Viewed block from core file.
I wrote config.xml for this but on product page I ma not able to do this.
Basically I want to overide Reports product block and want to append some code in that for the recent product slider.
my config.xml is
----------------
<?xml version="1.0"?>
<config>
<modules>
<Deepak_Recent>
<version>0.1.0</version>
</Deepak_Recent>
</modules>
<global>
<blocks>
<recent>
<rewrite>
<reports_product_viewed>Deepak_Recent_Block_Product_Viewed</reports_product_viewed>
</recent>
</catalog>
</blocks>
<helpers>
<recent>
<class>Deepak_Recent_Helper</class>
</recent>
</helpers>
</global>
<frontend>
<routers>
<recent>
<use>standard</use>
<args>
<module>Deepak_Recent</module>
<frontName>recent</frontName>
</args>
</recent>
</routers>
<layout>
<updates>
<recent>
<file>recent.xml</file>
</recent>
</updates>
</layout>
</frontend>
</config>
my rewrite block
-----------------
<?php
class Deepak_Recent_Block_Product_Viewed extends Mage_Reports_Block_Product_Viewed{
public function getme(){ echo 'block loaded';}
}
my layout.xml
---------------
<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_product_view>
<reference name="product.info">
<block type="recent/product" name="product.info.recent" template="carousel/products_recent_horizontal.phtml"/>
</reference>
</catalog_product_view>
</layout>
and alst my phtml file
-----------------
<?php
echo $this->getme();exit;
?>
your config.xml file should be
<config>
<modules>
<Deepak_Recent>
<version>0.1.0</version>
</Deepak_Recent>
</modules>
<global>
<blocks>
<reports> <!-- Changes here start -->
<rewrite>
<product_viewed>Deepak_Recent_Block_Product_Viewed</product_viewed>
</rewrite>
</reports> <!-- Changes here end -->
</blocks>
<helpers>
<recent>
<class>Deepak_Recent_Helper</class>
</recent>
</helpers>
</global>
<frontend>
<routers>
<recent>
<use>standard</use>
<args>
<module>Deepak_Recent</module>
<frontName>recent</frontName>
</args>
</recent>
</routers>
<layout>
<updates>
<recent>
<file>recent.xml</file>
</recent>
</updates>
</layout>
</frontend>
</config>
Actually issue was in
<blocks>
<reports> <!-- Changes here start -->
<rewrite>
<product_viewed>Deepak_Recent_Block_Product_Viewed</product_viewed>
</rewrite>
</reports> <!-- Changes here end -->
</blocks>

How to load phtml file in magento admin

app\code\local\Stw\Tree\Block\Adminhtml\Adminblock.php
<?php
class Stw_Tree_Block_Adminhtml_Adminblock extends Mage_Adminhtml_Block_Template
{
public function __construct()
{
parent::__construct();
}
protected function _prepareLayout()
{
return parent::_prepareLayout();
}
public function getHandleUpdates()
{
Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles());
}
}
app\code\local\Stw\Tree\controllers\Adminhtml\CustomController.php
class Stw_Tree_Adminhtml_CustomController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->_setActiveMenu('mycustomtab');
$this->renderLayout();
}
}
app\design\adminhtml\default\default\layout\tree.xml
<?xml version="1.0"?>
<layout>
<default>
<reference name="content">
<block type="tree/adminhtml_adminblock" name="tree" template="tree/myform.phtml" />
</reference>
</default>
</layout>
app\code\local\Stw\Tree\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Stw_Tree>
<version>1.0.0</version>
</Stw_Tree>
</modules>
<global>
<helpers>
<stw_tree>
<!-- Helper definition needed by Magento -->
<class>Mage_Core_Helper</class>
</stw_tree>
</helpers>
<blocks>
<stw_tree>
<class>Stw_Tree_Block</class>
</stw_tree>
</blocks>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<stw_tree before="Mage_Adminhtml">Stw_Tree_Adminhtml</stw_tree>
</modules>
</args>
<layout>
<updates>
<tree>
<file>tree.xml</file>
</tree>
</updates>
</layout>
</adminhtml>
</routers>
</admin>
</config>
I want load myform.phtml in admin section of magento, but nothing is loading. I am not understanding what is wrong in that. please someone tell me changes. myform.phtml contains pure HTML code
As defined block in config.xml as below :-
<blocks>
<stw_tree>
<class>Stw_Tree_Block</class>
</stw_tree>
</blocks>
You need to use same alias to call this block from Layout as below :-
<layout>
<default>
<reference name="content">
<block type="stw_tree/adminhtml_adminblock" name="tree" template="tree/myform.phtml" />
</reference>
</default>
</layout>
I don't believe the layout node should be inside the router note like that in your config.xml file. You should add a new adminhtml node as a sibling to admin, i.e. a direct child of config.
</admin>
<adminhtml>
<layout>
<updates>
<tree>
<file>tree.xml</file>
</tree>
</updates>
</layout>
</adminhtml>
</config>

Resources