Looks like your admin route declaration is incorrect. Try this:
<admin>
<routers>
<adminhtml>
<args>
<modules>
<TwilitGrotto_AutoCustomerLookup after="Mage_Adminhtml">TwilitGrotto_AutoCustomerLookup</TwilitGrotto_AutoCustomerLookup>
</modules>
</args>
</adminhtml>
</routers>
</admin>
Here is a good article on the topic: Magento Admin Hello World Revisited
EDIT:
I'm posting a working solution below:
File: TwilitGrotto\AutoCustomerLookup\etc\adminhtml.xml
<?xml version="1.0"?>
<config>
<acl>
<resources>
<admin>
<children>
<sales>
<children>
<twilitgrotto_autocustomerlookup translate="title" module="twilitgrotto_autocustomerlookup">
<title>Auto Customer Lookup</title>
</twilitgrotto_autocustomerlookup>
</children>
</sales>
</children>
</admin>
</resources>
</acl>
</config>
File: TwilitGrotto\AutoCustomerLookup\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<TwilitGrotto_AutoCustomerLookup>
<version>1.0.0.0</version>
</TwilitGrotto_AutoCustomerLookup>
</modules>
<global>
<helpers>
<twilitgrotto_autocustomerlookup>
<class>TwilitGrotto_AutoCustomerLookup_Helper</class>
</twilitgrotto_autocustomerlookup>
</helpers>
</global>
<adminhtml>
<layout>
<updates>
<twilitgrotto>
<file>twilitgrotto_autocustomerlookup_layout.xml</file>
</twilitgrotto>
</updates>
</layout>
</adminhtml>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<TwilitGrotto_AutoCustomerLookup after="Mage_Adminhtml">TwilitGrotto_AutoCustomerLookup_Adminhtml</TwilitGrotto_AutoCustomerLookup>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
File: TwilitGrotto\AutoCustomerLookup\controllers\Adminhtml\Autocustomerlookup\AddressController.php
<?php
class TwilitGrotto_AutoCustomerLookup_Adminhtml_Autocustomerlookup_AddressController
extends Mage_Adminhtml_Controller_Action
{
public function checkEmailExistsAction()
{
$emailAddress = $this->getRequest()->getParam('emailAddress');
$result = Mage::helper('twilitgrotto_autocustomerlookup')->checkEmailExists($emailAddress);
$this->getResponse()->setBody($result);
}
protected function _isAllowed()
{
return Mage::getSingleton('admin/session')->isAllowed('sales/twilitgrotto_autocustomerlookup');
}
}
Controller URL: Mage::getUrl('adminhtml/autocustomerlookup_address/checkEmailExists');
below is the example how to do this, Please modify it according to your requirement.
I used js template for this.
Following example will create drop down in your phtml file using ajax functionality.
In your JS
define([
'jquery',
'underscore',
'mage/template',
'jquery/list-filter'
], function (
$,
_,
template
) {
function main(config, element) {
var $element = $(element);
var YOUR_URL_HERE = config.AjaxUrl;
$(document).on('click','yourID_Or_Class',function() {
var param = 'ajax=1';
$.ajax({
showLoader: true,
url: YOUR_URL_HERE,
data: param,
type: "POST",
dataType: 'json'
}).done(function (data) {
$('#test').removeClass('hideme');
var html = template('#test', {posts:data});
$('#test').html(html);
});
});
};
return main;
});
In Controller
public function __construct(
Context $context,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
) {
$this->resultJsonFactory = $resultJsonFactory;
parent::__construct($context);
}
public function execute()
{
$result = $this->resultJsonFactory->create();
if ($this->getRequest()->isAjax())
{
$test=Array
(
'Firstname' => 'What is your firstname',
'Email' => 'What is your emailId',
'Lastname' => 'What is your lastname',
'Country' => 'Your Country'
);
return $result->setData($test);
}
}
IN your phtml file
<style>
.hideme{display:none;}
</style>
<script type="text/x-magento-init">
{
"*": {
"[Namespace]_[Modulename]/js/YOURFILE": {
"AjaxUrl": "<?php echo $block->getAjaxUrl(); ?>",
}
}
}
</script>
<div id='test' class="hideme">
<select>
<% _.each(posts, function(text,value) { %>
<option value="<%= value %>"><%= text %></option>
<% }) %>
</select>
</div>
getAjaxUrl should be function in your block file, which return you the url
Hope that helps.
Best Answer
ajax
you can use
ResultFactory
controller