I'm trying to send information from the view (js) to the server. I'm trying this with the JS request:

    type: 'POST',
    url: 'php_file_in_controller/Main_Class_Name',
    data: data,
    dataType: "json",
    success: function(responseData){
    fail: function(error){

This is my controller:

 namespace Magento\Checkout\Controller;

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

 public function execute(){
 ...some code..

} and my config.xml of the module:

<?xml version="1.0"?>
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">

The JS file is in the same module as the php file i am trying to send data to. I don't understand why I receive a 404. Is there a more convenient way to pass data from view to controller? If ajax is the way to go (for multiple reasons) what could be my problem? I'm using the checkout module in this situation so routes.xml is not a problem (or is it..?) Thanks in advance.

  • please provide detail code including your config.xml and your controller file – Murtuza Zabuawala Sep 26 '16 at 3:20
  • I added my config.xml and my controller, Thanks – N. Mantel Sep 26 '16 at 5:07

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.