Diazo adds unwanted html header to json response

I have an empty Plone 4.1 website with only the team installed. The download portlet worked fine until I installed plone.app.theming and applied my theme. Files were uploaded, but the web client received the status "Failed".

While checking the ajax response from the server, I found that they were wrapped with an html header. The old answer (before installing diazo and apply my theme) was just

{"success":true} 

The new answer (after installing diazo and apply my theme) was wrapped with the 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 have attached my rule.xml file here (nothing special, there is only one rule due to css: if-content = "# visual-portal-wrapper"): http://pastebin.com/SaK13Fni

What should I do to get around this?

thanks

+6
source share
2 answers

To avoid this behavior, you should add an exception to your rules.xml , which indicates not to apply your theme to your specific view, for example:

 <notheme if-path="myjson_view"/> 

change

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

  • modify your rules.xml as follows:

      <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> 
  • 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, maybe a problem.

+8
source

Make sure to use the Chrome inspector ... it adds the html head and pre tags around your json when you check it ... this is actually not the case if you look at the view: page source (old school) .. .

0
source

Source: https://habr.com/ru/post/897807/


All Articles