magento自带了prototype这个JS框架,因为prototype封装了常用的ajax功能,所以magento也可以很方便的使用ajax。
jsfile.js 代码如下,注意url是https的别忘了s
jsfile.js 代码如下,注意url是https的别忘了s
var url = 'https://www.domain.net/your_module/your_controller/getdata/'
function getalldata(url)
{
new Ajax.Request(url, {
method: 'get',//'post'
onSuccess: function(text) {
yourtext = text.responseText.evalJSON(true);
//process something
},
onFailure: function() {
return false;
},
onException: function() {
return false;
}
});
return true;
}
phtml中引入js文件
<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/jsfile.js') ?>"></script>
php文件,/your_module/your_controller.php
protected function getdataAction() {
$mydata = array();
//processing ... ...
echo Zend_Json::encode($mydata);
}