Unexpected token '(' : <p>I am trying to make a shortcut to fire alerts in my admin system, but I am getting a weird "Unexpected token" error I can't understand.</p>

<p><strong>My code</strong></p>

<pre><code>$( document ).ready(function(

    /**
     *          POST.JS
     *
     * Usage success:
     *
     * json_encode([
     *      'ok' =&gt; true,
     *      'message' =&gt; $this-&gt;language-&gt;get('text_success')
     * ]);
     *
     * Usage
     *
     * json_encode([
     *      'ok' =&gt; false,
     *      'message' =&gt; $this-&gt;language-&gt;get('text_error'),
     *      'errors' =&gt; [
     *          $this-&gt;language-&gt;get('error_1'),
     *          $this-&gt;language-&gt;get('error_2')
     *      ];
     * ]);
     *
     */

    $('form[method=post]').submit(function( event ) {
        event.preventDefault();

        $.post($(this).attr('action'), $(this).serializeArray(), function(data) {
            if (typeof data.ok != 'undefined') {
                console.error('No success status defined!')

                return;
            }

            if (data.ok == true) {
                $('#dg-alert-message').html(data.message);
                $('#dg-alert').addClass('alert-success');
            } else {
                var errors = [];
                var html_list = '';

                $.each(data.errors, function(index, value) {
                    html_list += '&lt;li&gt;' + value + '&lt;/li&gt;';
                });

                $('#dg-alert-list').html(html_list);
                $('#dg-alert').addClass('alert-danger');
            }

            $('#dg-alert').show();
        }, 'JSON').error(function(a,b,c) {
            console.log(a,b,c);
        });
    });

));
</code></pre>

<p>The error I am getting is as followed:</p>

<pre><code>post.js:26 Uncaught SyntaxError: Unexpected token (
</code></pre>

<p>Rule 26 of the file post.js is:</p>

<pre><code>$('form[method=post]').submit(function( event ) {
</code></pre>

<p>The script tag in the footer looks as followed, and jQuery is loaded before this script file:</p>

<pre><code>&lt;?php if ($logged) { ?&gt;
    &lt;!-- DoubleGuns scripts --&gt;
    &lt;script src="view/javascript/doubleguns/post.js"&gt;&lt;/script&gt;
&lt;?php } ?&gt;
</code></pre>

<p>What I have tried more:</p>

<ul>
<li>form[method="post"] in jQuery tag</li>
<li>Checked or jQuery was loaded (script starts with $(document).ready() so is unpossible</li>
<li>Changed submit event to a on('submit', function()) event</li>
<li>$logged returns true</li>
</ul>

<p>help?</p>
