Search code examples
javascripthtmljquery

Jquery : Uncaught SyntaxError: Failed to execute 'appendChild' on 'Node': missing ) after argument list


I'm trying to upload an image with jquery $.ajax method. I have been using the $.ajax code since many years, but strangely it is not working on this particular project. Here is the code

 <form id="adimgform">
       <input type="file" id="adimage" name="adimage" accept="image/png, image/gif, image/jpeg, image/webp" required>
 </form>   

Javascript code

$('#adimage').change(function(){
    uploadimage();
});

function uploadimage()
{
                const adimgform = new FormData($('#adimgform')[0]);
        
                $.ajax({
                    url: '/controller/upload-ad-image.php',
                    type : 'POST',
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    data: adimgform,
                    enctype: 'multipart/form-data', 
                    success: function (returndata) {            
                    $('#adform1result').html(returndata);    
                    }
                }); 
}

And this is the error im getting

Uncaught SyntaxError: Failed to execute 'appendChild' on 'Node': missing ) after argument list
    at m (jquery-3.7.1.min.js:2:880)
    at $e (jquery-3.7.1.min.js:2:46274)
    at ce.append (jquery-3.7.1.min.js:2:47633)
    at ce.<anonymous> (jquery-3.7.1.min.js:2:48729)
    at M (jquery-3.7.1.min.js:2:29497)
    at ce.html (jquery-3.7.1.min.js:2:48405)
    at Object.success (post-now.php?category=1&name=Automobiles:220:41)
    at c (jquery-3.7.1.min.js:2:25304)
    at Object.fireWith [as resolveWith] (jquery-3.7.1.min.js:2:26053)
    at l (jquery-3.7.1.min.js:2:77782)

strangely, all other forms are working on this site, so im really confused. Any help would be much appreciated, please.


Solution

  • I have this error a lot before.

    The error (Uncaught SyntaxError: Failed to execute 'appendChild' on 'Node') indicates a syntax issue, often due to a missing closing parenthesis ), bracket ], or brace } in your code. The error is being triggered in a script that manipulates the DOM using jQuery.