What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hello guys how do I use ajax provider molecule to make a POST request with data in the body ?

UM9F81RCP
UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

Hello guys

how do I use ajax provider molecule to make a POST request with data in the body ?

Comments

  • Yuriy Gerton
    Yuriy Gerton Front End Technical Lead Sprykee Posts: 49 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hello Ahmad!
    Change the method attribute to POST in the include
    For example:

    {% include molecule('ajax-provider') with {
            attributes: {
                method: 'POST',
                url: 'Your URL',
            },
        } only %}
    
  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    nice but what if I want to send dat in the body ?

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    so this will send a post request to the given url … but where do I define the data for that post?

  • Yuriy Gerton
    Yuriy Gerton Front End Technical Lead Sprykee Posts: 49 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited January 2020

    By default, the ajax-provider molecule can add data for the POST requests only with the fetch method.

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    are you saying that I cannot send data with post in ajax provider?

  • Yuriy Gerton
    Yuriy Gerton Front End Technical Lead Sprykee Posts: 49 πŸ§‘πŸ»β€πŸš€ - Cadet

    If using only include the molecule in TWIG, unfortunately not.

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    ah ok

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    thank you mate πŸ™‚

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    one more question in the same topic

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    if the molecule is included and the ajax request does not appear in the browser console

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    what could be the problem?

  • Yuriy Gerton
    Yuriy Gerton Front End Technical Lead Sprykee Posts: 49 πŸ§‘πŸ»β€πŸš€ - Cadet

    Do you see the component in HTML debugger with correct attributes?

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    yes

  • Yuriy Gerton
    Yuriy Gerton Front End Technical Lead Sprykee Posts: 49 πŸ§‘πŸ»β€πŸš€ - Cadet

    Do you try to send this request by a trigger or by on load a page?

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    on page load

  • Yuriy Gerton
    Yuriy Gerton Front End Technical Lead Sprykee Posts: 49 πŸ§‘πŸ»β€πŸš€ - Cadet

    Did you change the fetch-on-load attribute on true because it’s false by default?

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    so now it actually works

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    but there is something wierd

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    the request happens twice

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    one of them gets canceled

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    the second succeeds

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    any idea?

  • Yuriy Gerton
    Yuriy Gerton Front End Technical Lead Sprykee Posts: 49 πŸ§‘πŸ»β€πŸš€ - Cadet

    Check duplication of the component in HTML

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    there is not duplication !

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    actually another widget I am using .. just works out of the box with out specifying this fetch on load attribute

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    Thanks a lot @UQRP02SP2

  • UM9F81RCP
    UM9F81RCP Posts: 516 πŸ§‘πŸ»β€πŸš€ - Cadet

    πŸ™‚