Dear Developers,
I have tried to implement ajax request and response in shopware 5. My code also given below.
In Frontend .tpl code :
$.ajax({
url: ‚{url controller=ControllerName action=myCustom}‘,
method: ‚POST‘,
}).then(function(response) {
console.log(response.msg);
});
In Frontend controller File :
public function myCustomAction() {
$this->Front()->Plugins()->ViewRenderer()->setNoRender();
$this->Front()->Plugins()->Json()->setRenderer();
$this->view->setTemplate();
$this->view()->assign(array('success',true,'msg'=> 'pointadded'));return;
}
Response From Controller :
{1: true, customerpoint: „1000“, msg: „pointadded“, httpCacheEnabled: true,…}
1: true
cookieGroups: [{name: „technical“, label: „Technically required“,…}, {name: „comfort“, label: „Comfort functions“,…},…]
0: {name: „technical“, label: „Technically required“,…}
1: {name: „comfort“, label: „Comfort functions“,…}
2: {name: „personalization“, label: „Personalization“, description: „“, cookies: , required: false}
3: {name: „statistics“, label: „Statistics & Tracking“, description: „“, cookies: [,…], required: false}
4: {name: „others“, label: „Others“, description: „“, cookies: , required: false}
customerpoint: „1000“
httpCacheEnabled: true
msg: „pointadded“
The "cookieGroups " data comes from core file.
File Path : engine/Shopware/Components/Privacy/CookieRemoveSubscriber.php
Function Name : onPostDispatch
Query :
How to avoid unwanted data from action (like cookieGroups, httpCacheEnabled). Please share your idea.