5

For my custom module i'm making a ajax call. during this ajax call a additional call ../customer/section/load/?sections=messages&update_section_id=true&_=1485355389960 getting triggered. Not sure this is called every time.

Anybody having idea over here?

3
  • 5
    Before asking a new question please accept all the answers in your previous questions , just saw your profile you are not accepting the answer from your question. you are kindly requested to help community to improve @seeni
    – Keyur Shah
    Commented Jan 25, 2017 at 15:17
  • @KeyurShah Sorry for that, I'm not sure how to accept a answer like putting a comment for answered person?
    – seeni
    Commented Jan 25, 2017 at 16:00
  • 3
    you can see tick-mark option near to answer , just click on that nothing else @seeni
    – Keyur Shah
    Commented Jan 25, 2017 at 16:02

3 Answers 3

8

the sections are part of the magento2 fpc hole punching mechanism.

It's a way of storing private customer data in the local storage and updating it on specific actions.

The mechanism is explained in the dev docs here: http://devdocs.magento.com/guides/v2.0/config-guide/cache/cache-priv-priv.html

all sections in the customerData, which are defined in any Vendor/Module/etc/frontend/sections.xml File will be updated on POST or PUT requests on the defined actions

The messages section is a special case, since it's updated on any action: https://github.com/magento/magento2/blob/2.1/app/code/Magento/Theme/etc/frontend/sections.xml#L10

I think this is just a default to enable any ajax call to add messages to the page.

This js component triggers the ajax call in this component: https://github.com/magento/magento2/blob/b1e56ed3b6f13f1ab780d8eddc33fc04cb6ecf75/app/code/Magento/Customer/view/frontend/web/js/section-config.js

You could try to override the section config for '*' by adding a module with a etc/frontend/sections.xml with the following content

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
    <action name="*">
    </action>
</config>

But, honestly, I think it will get merged and the original config will still be present. (Also the messages update trigger would be disabled for any action)

It should stop triggering, if you change your ajax call to a GET request (although this does not seem to be a 'nice' solution)

you could write a plugin on the \Magento\Customer\Block\SectionConfig class and just remove the messages section from your ajax call action I think

1
  • I am getting the 403 at the customer/section/load request sometimes, But I am not able to find the issue in the console as well. Any solution?
    – Rana Zain
    Commented Aug 29, 2023 at 6:48
27

I had same problem and solution is very simple. Set the global event false in your jQuery request. Magento will not be able to intercept your request in that case.

example:

$.ajax({
    url: webUrl,
    type: 'POST',
    dataType: 'json',
    global: false,
    contentType: "application/json; charset=utf-8",
    data: myJSON,
    success: function (data) {

      }
});
4
  • Can you let me know the file location? Commented Dec 15, 2017 at 6:55
  • You're asking for the file location of your custom ajax request? Because that's what we're talking about here... you should already know where that is. You can also change the request type from POST to GET and it will not trigger the customer/section/load call Commented Nov 15, 2019 at 0:51
  • @Surendra: very helpful, thank you
    – Guru
    Commented Jan 8, 2020 at 2:54
  • works like a charm. thank you!
    – magento68
    Commented Jan 13, 2021 at 3:26
0

Can you please elaborate more, customer/section/load json data is still displaying by trying the above solutions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.