[Solved] Why am I getting Uncaught Error: Syntax error, unrecognized expression in my JavaScript? [closed]


You should pass the nonce parameter with a valid nonce, when the server side code is called.

For example, assuming you’ve implemented your code into JavaScript file that you are including using the function wp_enqueue_script

wp_enqueue_script( 'my_js_file', 'http://www.yourwebsitedomain.com/your_js_file.js');

As the nonce must be generated in the server side you should call the wp_localize_script function to generate a global JavaScript variable with the nonce if the JavaScript file was enqueued (I’ll call the global variable, my_global_var):

wp_enqueue_script( 'my_js_file', 'http://www.yourwebsitedomain.com');
wp_localize_script( 'my_js_file', 'my_global_var', array('nonce'=> wp_create_nonce('epm_new_user')));

Now, in your JavaScript code you should edit the piece of code:

data:{
        action: 'epm_registration_process',
        epformdata: epmformdata
    }

as follows:

data:{
        action: 'epm_registration_process',
        nonce: my_global_var['nonce'],
        epformdata: epmformdata
    }

and that’s all.

1

solved Why am I getting Uncaught Error: Syntax error, unrecognized expression in my JavaScript? [closed]