0

vendor\module_name\view\adminhtml\templates\tab\customer_view.phtml

    <?php $buttonTitle = __('Invalidate Quotes');?>
<div class="fieldset-wrapper customer-information">
    <div class="fieldset-wrapper-title">
        <span class="title"><?php /* @escapeNotVerified */
echo __('Invalidate customer quote') ?></span>
    </div>
    <table class="admin__table-secondary">
        <tbody>
        <?php echo $block->getChildHtml(); ?>
        <tr>
            <th><?php /* @escapeNotVerified */
echo __('Customer ID:') ?></th>
            <td><?php echo $block->getCustomerId(); ?></td>
        </tr>
        <tr>
            <th><?php /* @escapeNotVerified */
echo __('Invalidate Active Quote:') ?></th>
            <td>

            <div class="pp-buttons-container">
                <button class="import" id="<?php echo $block->getId() ?>" onclick="return false;">
                    <span><span><span><?php echo 'Remove Active Quote'; ?></span></span></span>
                </button>
            </div>

            </td>
        </tr>
        </tbody>
    </table>
</div>

<script type="text/javascript">
    require(["jquery",'mage/url'], function($, url){
        "use strict";
        $(document).on('click','.col-action-grouped a',function(){
        });

        $(document).on('click','.import',function(){
            jQuery.ajax({
            url: "/invalidatequote/index/quote",
            type: "POST",
            dataType: 'json',
            data: {data:'success'},
            success: function(response){

                console.log('Sucess');
            }
        });
        });

    });
</script>

My controller vendor\module_name\Controller\Adminhtml\Index\Quote.php

 <?php

namespace vendor\module_name\Controller\Adminhtml\Index;

class Quote extends \Magento\Backend\App\Action
{
    protected $resultPageFactory;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\Controller\Result\JsonFactory $resultPageFactory
    ) {
        parent::__construct($context);
        $this->resultPageFactory = $resultPageFactory;
    }

    public function execute()
    {
        if ($this->getRequest()->isAjax()) {

            echo "Testing";
        }

        return false;
    }
}

Request URL: https://localhost/admin/customer/index/edit/id/710825/key/51d5c1c3a251b6c0ce8b36ce3d832b2b1f359c8f073691f8c1df296ebf4a22c5/invalidatequote/index/quote?isAjax=true

Request Method: POST

Status Code: 200

Remote Address: 192.168.100.101:443

Referrer Policy: no-referrer-when-downgrade

routes.xml vendor\module_name\etc\adminhtml\routes.xml

    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route id="invalidatequote" frontName="invalidatequote">
            <module name="module_name" before="Magento_Backend"/>
        </route>
    </router>
</config>
20
  • Testing printed in response or not? Dec 16 '19 at 13:12
  • not getting any response Dec 16 '19 at 13:13
  • can u please print Testing outside function and check Dec 16 '19 at 13:14
  • 2
    Please write base_url/invalidatequote/index/quote in browser directly and check your contoroller called or not. we just want to check if your controller called successfully so we need to only check in phtml file Dec 16 '19 at 13:33
  • 1
    e.g, this is your base_url => localhost.com/, type something like this and hit localhost.com/admin/invalidatequote/index/quote Dec 16 '19 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.