javascriptjqueryajaxajaxformjqueryform

JQuery form API throwing the error Unexpected token (


I'm using jquery and jquery form API for image upload with PHP, when I use callback anonymous functions for jquery form API it keep throwing me this error on every anonymous function,

Uncaught SyntaxError: Unexpected token (

I can't even use any other jquery function with this code also, maybe if I fix this error it'll work,

my code is

$(function() {
  // bind 'myForm' and provide a simple callback function 
  $('#myForm').ajaxForm(function() {
    beforeSend: function() {
      alert('before send');
      $('#form-asset-create').validate();
    },
    uploadProgress: function() {},
    success: function() {},
    compile: function() {}
  });
  $(".card").hide();
});

Solution

  • You should pass object literal with config options to ajaxForm instead of a function.

    $(function() {
      // bind 'myForm' and provide a simple callback function 
        $('#myForm').ajaxForm({
        beforeSend: function() {
          alert('before send');
          $('#form-asset-create').validate();
        },
        uploadProgress: function() {},
        success: function() {},
        compile: function() {}
      });
      $(".card").hide();
    });