A
A
Alexander2020-12-25 20:49:48
1C-Bitrix
Alexander, 2020-12-25 20:49:48

Why is the isAjaxRequest method not working correctly in the news component?

I created a template for the news component, which in ajax mode filters blocks of articles by parameters, when you click the filter on the tag name, only those articles that have this tag remain on the page. Filtering works fine.

But at the same time, the component does not work correctly if you click on a regular link!
Each of the blocks has links - each link leads to the same page where the news component is located, but the article parameter (for example, technology or line of business) is also passed in the get request.

When clicking on the link, the user must go to this page again, where the news component will display articles for him, but already filtered by the tag that is in the GET request, for example, when clicking on the E-commerce link, the user will go to
the same page, but only articles that have the E-commerce tag will be displayed.

5fe62613c302a451094299.jpeg

If I follow this link from another page, everything works fine, but if I click on the news block, which is on the same page where the component call is located, the transition does not work , the component accepts such a click as an ajax request and does not work correctly (returns json instead of a simple redirect to its own page).

In the component template in the result_modifier file, I have a check:

$request = Context::getCurrent()->getRequest();
if($request->isAjaxRequest()){   
  …
}


But when I follow the link from the page where the component itself is located, isAjaxRequest () works as if it were an Ajax request. What could be the reason why the component perceives a simple click on a link as an ajax request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kalapanga, 2017-02-20
@kalapanga

Sorry for the offtopic, but I couldn't resist!
The inscription in the title of the program window on the screenshot: "The Enigma Protector Cracked By FRADDY RAD 2017"
An excellent protection program that cannot protect itself. Definitely worth using! :-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question