views:

401

answers:

2

Hi,

I am using the ajax uploader and the Zend Framework.

The Problem is when I am using the json response for the onSubmit. With $this->getHelper('Json')->sendJson($data); I only get a saveas dialog.

The problem is that the uploader expects every responste to be "text/html" but the json helper sends "application/json" as mimetype.

With a usual response every thing works fine, but I need to send some information back to the script.

So how can I say Zend that it should send jsondata with the mimetype "text/html"?

+4  A: 

You can affect the response by using the response object. From within your controller:

$content = Zend_Json::encode(array('Foo' => 'Nice', 'Bar' => 'Vice'));
$this->getResponse()
     ->setHeader('Content-Type', 'text/html')
     ->setBody($content)
     ->sendResponse();
exit();
karim79
This does not use the sendJson() action helper, but there aren't any options for that method. Use Zend_Json::encode() to encode your data and send it yourself using this method.
Kekoa
Thanks Kekoa, noted and incorporated.
karim79
to output valid json code you have to change your last line to:`->setBody($content)` and add: `->sendResponse(); exit();` otherwise Zend will surround the json data with your default style
@axel.klein - I've edited the answer based on your comment. Thanks, and sorry I forgot to include the sendResponse bit, I normally grab the response into a variable before outputting.
karim79
A: 

Yet another variant

echo Zend_Json::encode(array('result' => true));
exit;
Pavel