Im try to pass sql query value as an AJAX request, It have a array object I need to pass only the value, below code for that
public function execute()
{
$resultJson = $this->resultJsonFactory->create();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$sql = "SELECT price_component FROM base_price WHERE width =".$this->getRequest()->Width." AND height =".$this->getRequest()->Height;
$result = $connection->fetchAll($sql);
return $resultJson->setData($result);
}
if I used below code in .phtml class
.done(function(data) {
console.log(data);
});
result will be like below
[{…}]
0
:
{price_component: "122"}
length
:
1
__proto__
:
Array(0)
If i use result[0] index it will be like JSON object like below
{price_component: "132"}
price_component
:
"132"
__proto__
:
Object
I just need to get value to the console how can I do that