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

Uncaught SyntaxError: missing } after property list in AJAX

i am doing a little project in laravel with Ajax but i have got this error when i do the validations with ajax.

dashboard

<script>

$(document).ready(function() {

    $(document).on('click','.add_product', function(e) {
        e.preventDefault();

        let name= $('#name').val();
        let price= $('#price').val();

        $.ajax({
            url: {{ route('add') }},
            method: 'post',
            data: {name:name, price:price},
            success: function(res) { },
            error: function(err) {
                let error = err.responseJSON;

                $.each(error.errors, function(index, value) {
                    $('.errMsgContainer').append('<span class="text-danger">'+ value+ '</span>' + '<br>');
                });
            }
        });
    });

});
</script>

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

>Solution :

inside the ajax in the url make it like this

URL: "{{ route('add') }}",

add the route inside quotations.

    <script>
        $(document).ready(function() {

            $(document).on('click', '.add_product', function(e) {
                e.preventDefault();
                let name = $('#name').val();
                let price = $('#price').val();
                $.ajax({
                    url: "{{ route('add') }}",
                    method: 'post',
                    data: {
                        name: name,
                        price: price
                    },
                    success: function(res) {

                    },
                    error: function(err) {

                        let error = err.responseJSON;
                        $.each(error.errors, function(index, value) {
                            $('.errMsgContainer').append('<span class="text-danger">' + value + '</span>' + '<br>')
                        });
                    }
                });


            })

        });
    </script>
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