W
W
WebforSelf2021-09-16 11:17:11
JavaScript
WebforSelf, 2021-09-16 11:17:11

Why does firefox return json instead of page?

There is a site - link
I go to the site through Firefox, select any product filters and click find.
in response, it redirects to a page with a Json array. It's in the mazilla.
6142fd851f685264204000.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Flying, 2021-09-16
@WebforSelf

This is due to the incorrect organization of work with HTTP.
You are requesting data via XMLHttpRequest the GET method and at the same url as the page itself. As a result, it turns out that you have the same HTTP method and the same url give two different responses depending on ... don’t understand what (apparently the header is checked X-Requested-With), but this is clearly not what is described in the HTTP specification.
The key point, of course, is that the request goes by the GET method. If you have read the HTTP specification , or at least articles about the HTTP protocol, you should remember that the GET method is idempotent. It follows that the client (in this case, the browser) has every right (if caching conditions allow) to expect that it will receive the same response to this request and can optimize this by using the result already in the cache. That is exactly what is happening.
You can make sure that this is the case very simply: just open dev.tools and on the Network tab enable the "Disable cache" option. After that, you will see that the problem has disappeared.
The correct solution would be to separate the API for XHR filter requests into a separate endpoint. It also makes more sense to use the POST method rather than the GET method.
If you don’t want to redo it, at least add one more query parameter to XHR requests, for examplexhr=1and make sure it never appears in the url of the pages. This will make your urls for pages and XHR requests different and fix the problem.
It also makes sense to reconsider the amount of data transmitted in response to each request, because you only need values, it makes little sense to constantly transfer almost 100kb of description text, you already have them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question