如 /app/code/local/Xinson/News/controllers/Adminhtml/NewsController.php 的editAction() 方法
$this->renderLayout() 之前加
$this->_addContent($this->getLayout()->createBlock('core/text')->setText("
document.getElementById('placeholder_limit').onblur = function(){
var url = 'http://test.shop.com/serial-codes/';
new Ajax.Request(url, {
method: 'post',
onSuccess: function(text) {
//yourtext = text.responseText.evalJSON(true);
document.getElementById('placeholder_limit').parentNode.innerHTML += '';
},
onFailure: function() {
return false;
},
onException: function() {
return false;
}
});
return true;
}
"));
还有另外一种在/app/code/local/Xinson/News/controllers/Adminhtml/News/Edit.php 的 __construct()
最后加
$this->_formScripts[] = "
document.getElementById('placeholder_limit').onblur = function(){
var url = 'http://test.shop.com/serial-codes/';
new Ajax.Request(url, {
method: 'post',
onSuccess: function(text) {
},
onFailure: function() {
return false;
},
onException: function() {
return false;
}
});
return true;
}
";
本文介绍了如何在Magento Adminhtml NewsController中使用AJAX技术,在editAction方法中通过`_addContent`添加动态内容,以及另一种在构造函数中注入onblur事件的方法。展示了如何通过URL发送POST请求并处理响应结果。
222

被折叠的 条评论
为什么被折叠?



