vincent15000's avatar

PUT request from AlpineJS and dynamic property with a child component

Hello,

I'm trying to use AlpineJS to trigger a PUT request to update a model without refreshing the page.

Here is my code.

// my editor blade component

// the comment blade component

I get this error in the console.

Alpine Expression Error: missing ) after argument list

Expression: "{
        showForm: false,
        body: 'body',
        save: () => {
            axios.put('http://localhost:8000/articles/01k5f77cyybjdbhm34k1symzf3/comments/01k5gtfggyymedqxvz9253kr1k', { body: this.body })
                .then(response => {
                    console.log('Commentaire enregistré avec succès', response.data);
                })
                .catch(error => {
                    console.error('Erreur lors de l'enregistrement du commentaire :', error);
                });
        },
    }"

If I remove this part of the code (have a look just below), I don't get any error any more, but sure I need this part of the code.

.then(response => {
    console.log('Commentaire enregistré avec succès', response.data);
})
.catch(error => {
    console.error('Erreur lors de l'enregistrement du commentaire :', error);
});

Here is my questions : what am I doing wrong to get this error ?

And another question : not tested yet, given that I get this error, but is the body variable updated each time I update the textarea with the current code ? I don't think so.

Thanks for your help.

V

0 likes
4 replies
JussiMannisto's avatar
Level 50

You have an unescaped apostrophe in a string:

- console.error('Erreur lors de l'enregistrement du commentaire :', error);
+ console.error('Erreur lors de l\'enregistrement du commentaire :', error);
1 like
vincent15000's avatar

Wow I am probably tired ... Not at home non, but I will check as soon as possible. Thank you.

Please or to participate in this conversation.