'On button click save a flag to database in mediawiki 1.3

I am a fresher in mediawiki. I was trying to implement Manual:Tag extensions/Example (https://www.mediawiki.org/wiki/Manual:Tag_extensions/Example). But the example is based on mediawiki version < 1.3. I have a submit button. I want to save the current user name and a flag (say 1) to a database table if the submit button is clicked. but I am getting Uncaught SyntaxError: Unexpected identifier (at load.php?lang=en&modules=ext.Example.welcome%7Cjquery&skin=vector&version=h3cy2:1:383).

Can I anyone suggest how to resolve the issue My hook

class PollHooks implements
\MediaWiki\Hook\ParserFirstCallInitHook
{
Public function onParserFirstCallInit( $parser ) {
    $parser->setHook( 'btn', [ self::class, 'pollRender' ] );
    //$parser->setHook( 'poll', [self::class, 'pollRender' ] ); 
}
public static function pollRender( $data, $attribs, $parser, $frame ) {
    $ret = '<table class="wtable">';
    $ret .= '<tr>';
    $ret .= '<td align="center" colspan=2><input id="btn002" type="button" value="Submit"></td>';
    $ret .= '</tr>';
    $ret .= '</table>';
    return $ret;
}

My index.js

( function () {
$("#btn001").click
        (
            function() {
                alert("Button clicked " + mw.user.getName() + ".");
                
                console.log("Button clicked.");
                $var user = mw.user.getName();
                $flag = 1;
                
                $.get(
                        mw.util.wikiScript(),
                        {
                            action: 'ajax',
                            rsargs: [user, flag],
                            rs: 'MediaWiki\\Extension\\Example\\SubmitApi'
                        }
                );
            }
        );

}() );

SubmitApi.php

use ApiBase;

use Wikimedia\ParamValidator\ParamValidator;

class SubmitApi extends ApiBase {

public function execute() {
    /* … */
    global $wgUser;
    
    
    $dbw = wfGetDB( DB_REPLICA );
    
    // Insert vote
    $insertQuery = $dbw->insert(
                   'polldb',
                    array(
                        'poll_user' => $user,
                        'poll_flag' => $flag
                    )
    );
    $dbw->commit();
}

public function getAllowedParams() {
    return [
        'level' => [
            ParamValidator::PARAM_TYPE => 'integer',
            ParamValidator::PARAM_REQUIRED => true,
        ]
    ];
}

} ?>



Solution 1:[1]

index.js:

$var user = mw.user.getName();

Remove the $ from $var.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alexander Mashin