Here is my Ajax Call. I call it inside click() function with jQuery.
var customurl = gpImageTagLoadUrl + '?isAjax=true';
$.ajax({
url: customurl,
method: 'POST',
data: {element_id: 11},
dataType: 'json',
success: function (data) {
console.log(data.element_id);
}
});
In the other Script i call:
window.gpImageTagLoadUrl = '<?= /** @noEscape */ $this->getUrl('pluginName/caller/loadproduct')?>';
Inside the php function I call the execute function:
public function execute()
{
$variable = $this->configs->create();
$item = $variable->addFieldToFilter('id', 11);
return $item;
}
I can call this function but i get this error:
InvalidArgumentException): Invalid return type
Any Ideas? What is the right way to create Ajax Load Function in Magento 2?