Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

UUID value as function argument – Uncaught SyntaxError

I have a function which takes an "id" as argument:

<script>
    function deleteBl(id){
        fetch('', {
            method: 'DELETE',
            headers: {
                'X-CSRFToken': '{{ csrf_token }}'
            },
            body: JSON.stringify({
                'id': id
            }),
            credentials: 'same-origin',
        })
    }

</script>

and below Django template:

    {% for item in bl_query_set %}
    <tr>
        <th scope="row">{{ forloop.counter }}</th>
        <td>{{ item.bl_number }}</td>
        <td class="text-center">{{ item.cargo_name }}</td>
        <td>{{ item.cargo_quantity }} {{ item.cargo_measurement }}</td>
        <td>
            <a onclick="deleteBl({{ item.id }})">
                <i class="fas fa-trash-alt"></i>
            </a>
        </td>
    </tr>
    {% endfor %}

There are no any console errors if I use default Id as primary key. But I need to use UUID as a primary key and in that case I get an error: "Uncaught SyntaxError: Invalid or unexpected token":

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

How I can resolve mentioned issue?

>Solution :

You need to pass it as a string:

<a onclick="deleteBl('{{ item.id }}')">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading