I am trying to get input data in the controller but controller not getting url params.
<?php
namespace Crud\Crudatfrontend\Controller\Result;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\Controller\Result\JsonFactory;
class Result extends \Magento\Framework\App\Action\Action
{
/**
* @var Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
protected $resultJsonFactory;
/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory,
JsonFactory $resultJsonFactory
)
{
$this->resultPageFactory = $resultPageFactory;
$this->resultJsonFactory = $resultJsonFactory;
return parent::__construct($context);
}
public function execute()
{
var_dump($this->getRequest()->getParams());die("testing");
//echo '<pre>';
//print_r($this->getRequest('height')->getParams());exit;
$height = $this->getRequest()->getParam('height');
//$height = 5;
$weight = $this->getRequest()->getParam('weight');
$result = $this->resultJsonFactory->create();
$resultPage = $this->resultPageFactory->create();
$block = $resultPage->getLayout()
->createBlock('Crud\Crudatfrontend\Block\Index')
->setTemplate('Crud_Crudatfrontend::result.phtml')
->setData('height',$height)
->setData('weight',$weight)
->toHtml();
$result->setData($block);
return $result;
}
}
Here is my phtml file
<div class="row clearfix">
<div class="col-md-12 column">
<form name="form_height" method="POST" id="form_height">
<input type="text" name="height" class="form-control input-md">
<input type="text" name="weight" class="form-control input-md">
<input type="submit" id="calculateTotalSubmit" name="calculate-total-submit" value="Calculate Total">
</div>
</form>
</div>
</div>
<script>
require(['jquery'],function(){
jQuery(document).ready(function() {
alert("hi")
jQuery("#form_height").submit(function(){
var heightValue = jQuery("input[name='height']").val();
var weightValue = jQuery("input[name='weight']").val();
var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
jQuery.ajax({
url: url,
type: "POST",
data: {height:heightValue,weight:weightValue},
//data: jQuery(this).serialize(),
success: function(response){
// alert(heightValue);
console.log(response.output);
window.location.href = url;
}
});
return false;
});
});
});
</script>
I am getting values in console.
\Magento\Framework\App\Request\Http