4

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?

  • 4
    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 Jan 25 '17 at 15:17
  • @KeyurShah Sorry for that, I'm not sure how to accept a answer like putting a comment for answered person? – seeni Jan 25 '17 at 16:00
  • 2
    you can see tick-mark option near to answer , just click on that nothing else @seeni – Keyur Shah Jan 25 '17 at 16:02
6

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

9

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) {

      }
});
  • Can you let me know the file location? – Palanikumar Dec 15 '17 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 – Andre Nickatina Nov 15 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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