Created
July 30, 2012 22:18
-
-
Save jacquesbh/3210926 to your computer and use it in GitHub Desktop.
[Blog] Jbh_Webservice (http://jacques.sh/vos-blocs-en-ajax-via-webservice.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!-- | |
/** | |
* This file is part of Jbh_Webservice for Magento. | |
* | |
* This program is free software. It comes without any warranty, to | |
* the extent permitted by applicable law. You can redistribute it | |
* and/or modify it under the terms of the Do What The Fuck You Want | |
* To Public License, Version 2, as published by Sam Hocevar. See | |
* http://sam.zoy.org/wtfpl/COPYING for more details. | |
* | |
* @license WTFPL | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Webservice | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
--> | |
<config> | |
<modules> | |
<Jbh_Webservice> | |
<version>0.1.0</version> | |
</Jbh_Webservice> | |
</modules> | |
<frontend> | |
<routers> | |
<jbh_webservice> | |
<use>standard</use> | |
<args> | |
<module>Jbh_Webservice</module> | |
<frontName>webservice</frontName> | |
</args> | |
</jbh_webservice> | |
</routers> | |
</frontend> | |
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This file is part of Jbh_Webservice for Magento. | |
* | |
* This program is free software. It comes without any warranty, to | |
* the extent permitted by applicable law. You can redistribute it | |
* and/or modify it under the terms of the Do What The Fuck You Want | |
* To Public License, Version 2, as published by Sam Hocevar. See | |
* http://sam.zoy.org/wtfpl/COPYING for more details. | |
* | |
* @license WTFPL | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Webservice | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
var BASE_ECOM_URL = 'http://example.org/'; | |
(function ($) { | |
$(document).ready(function () { | |
$.getJSON(BASE_ECOM_URL + 'webservice/page/footer?callback=?', function (data) { | |
$('#footer').replaceWith($(data.html)); | |
}); | |
}); | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<!-- | |
/** | |
* This file is part of Jbh_Webservice for Magento. | |
* | |
* This program is free software. It comes without any warranty, to | |
* the extent permitted by applicable law. You can redistribute it | |
* and/or modify it under the terms of the Do What The Fuck You Want | |
* To Public License, Version 2, as published by Sam Hocevar. See | |
* http://sam.zoy.org/wtfpl/COPYING for more details. | |
* | |
* @license WTFPL | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Webservice | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
--> | |
<config> | |
<modules> | |
<Jbh_Webservice> | |
<active>true</active> | |
<codePool>community</codePool> | |
</Jbh_Webservice> | |
</modules> | |
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2004 Sam Hocevar <[email protected]> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of Jbh_Webservice for Magento. | |
* | |
* This program is free software. It comes without any warranty, to | |
* the extent permitted by applicable law. You can redistribute it | |
* and/or modify it under the terms of the Do What The Fuck You Want | |
* To Public License, Version 2, as published by Sam Hocevar. See | |
* http://sam.zoy.org/wtfpl/COPYING for more details. | |
* | |
* @license WTFPL | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Webservice | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
/** | |
* Page Controller | |
* @package Jbh_Webservice | |
*/ | |
class Jbh_Webservice_PageController extends Mage_Core_Controller_Front_Action | |
{ | |
/** | |
* The query callback name | |
* @const QUERY_CALLBACK_NAME string | |
*/ | |
const QUERY_CALLBACK_NAME = 'callback'; | |
/** | |
* Retrieve the default footer :) | |
* @access public | |
* @return void | |
*/ | |
public function footerAction() | |
{ | |
// Load the layout and render ! | |
$this->loadLayout(); | |
// Remove the output for the root block | |
$this->getLayout()->removeOutputBlock('root'); | |
// Yeah ;) | |
$this->renderLayout('footer'); | |
} | |
/** | |
* Need JSONP ? We use the postDispatch. | |
* @access public | |
* @return void | |
*/ | |
public function postDispatch() | |
{ | |
// If we have an URL like .../?callback=callbackName | |
if ($callback = $this->getRequest()->getParam(self::QUERY_CALLBACK_NAME, false)) { | |
// We change the content :) | |
$body = $callback . '(' . json_encode(array('html' => $this->getResponse()->getBody())) . ')'; | |
$this->getResponse()->setBody($body); | |
} | |
return parent::postDispatch(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment