Joomla 3.4.5
components/com_virtuemart/controllers/plugin.php Line: 72 + 76
jExit();
makes the joomla exit with outputted data. This means no headers are set before output.
Im using example with parameters format=json
And this should be confirming that headers are not SENT before jexit();
they are just prepared
http://joomla.stackexchange.com/questions/1126/return-json-using-the-joomla-framework
So what do you suggest? We used jExit instead of die. So how do we sent the header?
should we use someting like
$this->app->mimeType = 'application/json';
??
Hi Milbo
Sry for the late reply. Im not sure why im not being notified for new entries in my thread. anyway - ill make sure ill check up a couple of times during day
Im not that much into the Joomla platform, but from what i can read around the web the problem that occours is that joomla exists without sending the headers. so the solution is to send the headers yourself.
Doing that lead me to an other problem. The mimetype was not printed either. so i have to manually set the content-type header
See my working code:
if ($format == 'json') {
$document->setMimeEncoding ('application/json');
// Change the suggested filename.
JResponse::setHeader ('Content-Disposition', 'attachment;filename="' . $type . '.json"');
JResponse::setHeader("Content-type","application/json");
JResponse::sendHeaders();
echo json_encode ($render);
jExit();
}
reading the platform api says that this method is deprecated:
https://api.joomla.org/cms-3/classes/JResponse.html#method_sendHeaders
They write that we should :
4.0 Use JApplicationWeb::sendHeaders() instead
However when i write that in that place the JApplicationWeb is not defined or instantiated or something..it fails.. but again i think the whole JResponse class will be deprecated and replaced by JApplicationWeb - so when VM is updated at some point in the future this will be handled by the new class i guess?
Again.. i dont know "much" about what happens in the core of VM, so i cannot say if everything is being dealt with with my code. but please feel free to change it the way you want and let me know if i can be of any assistance.
Have a great friday
perhaps someone from the development team can confirm this bug and tell me if the proposed fix is good enough, so i can go ahead and upgrade production på newest versions and make those hack (that will be overwritten once u release the next version)
oh sorry, I thought I answered you already. Yes your fix is quite adequate. I added almost the same now. You may check the svn at http://dev.virtuemart.net/projects/virtuemart/repository
Great
Thanks