2

I've written an ajax call to get some user specific content. But I found that the response of the ajax call is very slow. Indeed, I found that this is due to the slow response of the controller class. The controller class takes at least 2 seconds to give a empty json respnse while the controller is just a simple controller to handle the ajax call.

<?php

/**
 *
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Vendor\ModuleName\Controller\Program;

class TestAjax extends \Magento\Framework\App\Action\Action {

    public function __construct(
    \Magento\Framework\App\Action\Context $context
    ) {
        parent::__construct($context);
    }

    /**
     * Forgot customer account information page
     *
     * @return \Magento\Framework\View\Result\Page
     */
    public function execute() {
        $testing= null;

        $arr = array('testing' => $testing);
        $jsonData = json_encode($arr);
        $this->getResponse()->setHeader('Content-type', 'application/json');
        $this->getResponse()->setBody($jsonData);
        $this->getResponse()->sendResponse();
    }

}
3
  • Disabling the cache has a sense for some development tasks only & Caching definitely should be enabled in production mode
    – Vishal
    Commented Jun 16, 2016 at 5:27
  • Are you saying this controller action is specifically much slower than all other controllers on the same install? Commented Jun 16, 2016 at 8:36
  • Try do it more in magento way, like this, maybe it will be faster: magento.stackexchange.com/questions/99358/… Commented Dec 31, 2016 at 10:52

1 Answer 1

-1

Yes, I have also use the Ajax in magento2 and getting very slow response from controller

My Code is:

var param = {
    dDate: datem,
    user: <?php echo json_encode($username); ?>,
    courseid: <?php echo json_encode($courseid); ?>
};
 //var param = 'ajax=1&date='+datem+'&arr123='+jQuery.parseJSON(<?php echo json_encode($timeArr2,true); ?>);
 jQuery.ajax( {


url: '<?php echo $storeManager->getStore()->getBaseUrl(); ?>/wlcms/index/',
data: param,
type: 'GET',
dataType: 'json'

}).done(function(a) { 

     jQuery('#test').show();
    // alert(json_decode(a));                               
     jQuery('#test').html(a);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.