plonediazo

Diazo add unwanted html header into json response


I have a blank Plone 4.1 site with only collective.quickupload installed. The upload portlet worked fine until I install plone.app.theming and apply my theme. The files were still uploaded, but the web client got "Failed" status.

Inspecting the ajax response from server I found that they were wrapped by html header. The old response (before install diazo & apply my theme) was simply

{"success":true}

The new response (after install diazo and apply my theme) was being wrapped by a html tag:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><body><p>{"success":true}</p></body></html>

I've pasted my rule.xml file here (nothing special, there is only one rule conditioned by css:if-content="#visual-portal-wrapper"): http://pastebin.com/SaK13Fni

What should I do to work around this ?

Thanks


Solution

  • To avoid this behavior you have to add an exception in your rules.xml that specify to not apply your theme to your specific view , like this:

    <notheme if-path="myjson_view"/>
    

    edit:

    I've tried with one of my diazo themes and a json view and I didn't have your issue. So I think the problem is either in your rules.xml or in your json view. You should try one of these two way:

    1. change your rules.xml this way:

         <rules
          xmlns="http://namespaces.plone.org/diazo"
          xmlns:css="http://namespaces.plone.org/diazo/css"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      
          <!-- Prevent theme usage in zmi-->
          <rules css:if-content="#visual-portal-wrapper">
              <theme href="index.html" />
          </rules>
      
    2. have you already specified the "Content-type" of the output in your json view? Like this:

      self.request.response.setHeader("Content-type","application/json")
      return json_data
      

      If not, that's probably the problem.