TYPO3 remove cache comment for json view - json

I want to have a json output of my page, so I have a typoscript setup with
diableAllHeaderCode and additionalHeaders Content-Type: application/json
Everything is good for the first call after clearing caches, but after that the json format is invalid because typo3 adds a comment to the bottom of the page like <!-- Cached page generated _-_-_ _:_. Expires _-_-_ _:_ -->
Can I somehow remove that tag or prevent it from being rendered without blocking the whole caching mechanism ?
And I would like to not change the TypoScriptFrontendController.php directly but rather find a solution to manage this from my extension

That information is displayed only for development/debug environment.
Dependend on your TYPO3 version you could try to disable this kind of debugging with some typoscript:
either global with config.debug = 0
or specific for your pagetype you use to generate JSON: json.config.debug = 0 (assumed this page object is named json)
Otherwise you test your JSON on the production system.
or you save your output, remove the comment and feed the file to your further process.

Related

How to disable parser cache for when using extension in 1.33

I wrote an extension for one wiki page to get content from outside URL, I just put in that article, it will hook to my extension to call Changelog.php to execute Changelog::getLog()
getLog method using curl connects to outside the URL to get JSON content and re-format it to HTML string and return that string, they work perfectly in 1.27, but after I upgrade to 1.33, it still get the content I want, but it cached the result, when outside URL changes content it won't go with it, I need to edit and save the article to get the newest content, I try to add $parser->getOutput()->updateCacheExpiry(0); and $parser->disableCache(); in getLog method but nothing changed.

Get last segment of URL path with MVC Razor

I have this URL: http://localhost:.../home/blogpost/#'I want to get this string'
I get it when pressing:
#item.Title
#item.Title is from my database and that string will change. Now I need to get the 'I want to get this string' string on that page so that I can do a if statement with it, like this:
#if(#item.Title == 'I want to get this string')
Any suggestions?
The target attribute (the part of an URI after the #) is not sent to the server when the browser retrieves the page. So, you cannot get it out of a normal GET or POST request on the server at all.
That data is available in the browser, so you could access it using javascript of even CSS.
Using ajax techniques, you could load a skeleton page and send the target string yourself to the server and have it react to it, and only then load the rest of the page. A bit overkill for most uses I'm afraid and there are drawbacks as well (e.g. search engine might have more trouble to see your content).
It's easier to send the string to the server as a GET parameter if you have the level of control you seem to have. [simply replace the # with a ?], that will be sent to the server by the browser.
Do note that you should URLencode any data you add on to a URL ...

insert a new document json using http post apache solr

What I have: Apache Solr 5.2.1
What I want: add a new document in a specific core defined by me
example: address of the solr core -->
http://IP_ADDRESS:8984/solr/myCustom_core/
I want to add a document json formed by {"id":"00001","title":"my title"} to the core above directly from the browser's url bar.
Problem:
I'm trying to address this problem in such a way:
http://IP_ADDRESS:8984/solr/myCustom_core/update?wt=json&{add:{"id":"00001","title":"my title"}}&commit=true
The response of the browser is:
{"responseHeader":{"status":0,"QTime":88}}
However, when I check on the server side the new entry is not added.
Conversely,it is works if I try to add such a document using the submit command provided in the UI of Solr.
Can someone provide me the correct way to build the correct url address?
Thanks
EDIT: thanks to MatsLindh I solved my problem using this:
http://IP_ADDRESS:PORT/solr/myCustom_core/update?stream.body=<add><doc><field name="exampleField">example value</field></doc></add>&commit=true
You can use stream.body to send an arbitrary content stream through GET variables instead of using POST (or a regular body).
Be sure to perform appropriate escaping of the content you use in your URL.
You'll also have to perform a commit before the submitted content becomes searchable, either through commit=true in the request or by issuing a separate commit request.

CQ5 Invalid recursion selector value 'data' (data.json.jsp)

Let's say I have a page in CQ5. I created this page using a template with a single component, call it tableComp, and I hit at url Test.html. The component contains its standard JSP file but the page template being used also contains a specific JSP for JSON or XML rendering of custom data, not page data.
This JSP file for rendering would be named something like data.xml.jsp or data.json.jsp. To hit this rendering JSP for the page Test.html you would call /content/{org}/desktop/en_US/{name}/Test.data.json or /content/{org}/desktop/en_US/{name}/Test.data.xml.
The XML/JSON JSP would be called which contains code to just get values and print to the screen XML or JSON. Ex: Blah
Now I want to display information to the screen as a JSON output when I hit a new file named data.json.jsp. When hitting data.xml.jsp it works correctly and hits the JSP. When I do the exact same process for the data.json.jsp I then get the following.
Invalid recursion selector value 'data'
Cannot serve request to /content/{org}/desktop/en_US/{name}/Test.data.json in org.apache.sling.servlets.get.DefaultGetServlet
Request Progress:
0 (2015-07-22 18:10:06) TIMER_START{Request Processing}
0 (2015-07-22 18:10:06) COMMENT timer_end format is {<elapsed msec>,<timer name>} <optional message>
0 (2015-07-22 18:10:06) LOG Method=GET, PathInfo=/content/{org}/desktop/en_US/{name}/Test.data.json
I have tried adding a Pages.json.jsp file to the /libs/foundation/components/primary/cq/Page section as suggested in another forum but this did not help. The content of this Pages.json.jsp file was <%#include file="proxy.jsp"%>.
How can I get JSON to work for this type of request?
EDIT:
I have changed my original explanation to clarify my problem.
Looks like the request is being handled by the DefaultGetServlet which in turn uses the JsonRendererServlet to process your requests with .json extensions.
Since the JsonRendererServlet requires a numeric selector or the infinity selector, it throws the following error.
Invalid recursion selector value <<selector>>
However requesting /Test/_jcr_content.data.json would render the JSON data processed by the data.json.jsp instead of the DefaultGetServlet.

Backbone pushState is returning raw JSON data

I am attempting to implement pushstate for my Backbone/NodeJS application. If I go to the following route /testRoute/123 within the browser itself, from another view, the associated views to /testRoute/123 load.
However, if I manually enter /testRoute/123 in the address bar, the browser returns a raw JSON feed for the object with id '123'.
How do I force Backbone to load the views when manually entering a URL?
This is not something Backbone can do (hense why pushState is disabled by default). You have to setup your server to redirect those requests to the root so that your HTML loads and Backbone can handle the route.
This is stated in the Backbone documentation:
Note that using real URLs requires your web server to be able to correctly render those pages, so back-end changes are required as well. For example, if you have a route of /documents/100, your web server must be able to serve that page, if the browser visits that URL directly. For full search-engine crawlability, it's best to have the server generate the complete HTML for the page ... but if it's a web application, just rendering the same content you would have for the root URL, and filling in the rest with Backbone Views and JavaScript works fine.
In case #idbehold's answer wasn't specific enough, here's a more detailed response to the same question.
I highly recommend looking at those links at the bottom of the response as they were exactly what I was looking for when faced with the same bother...