Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReCAPTCHA couldn't find user-provided function: myCallBack

I'm trying to use ReCAPTCHA where I am getting following error.

ReCAPTCHA couldn't find user-provided function: myCallBack.

How can I solve this issue?

var verifyCallback3 = function(response) {
    if(response!=null){
        $("#rss").show();
    }
};

var myCallBack = function() {
    grecaptcha.render('html_element', {
        'sitekey' : '6sssfffffffffAAPfEI_RkbAlUuw5FA4p-kiGy5Nea',
        'callback' : verifyCallback3,
        'theme' : 'light',
        'type':'image'
    });
};
like image 494
Sheetal Sharma Avatar asked Jun 15 '17 12:06

Sheetal Sharma


3 Answers

Make sure your callback function is being defined in the global scope. For some reason, in production my function was not in this namespace.

In addition to:

function myCallback() { ... }

Make sure you directly assign it into the global space:

window.myCallback = myCallback;

You should be able to test whether this is your problem, my typing the function name at the Javascript console and seeing if it's defined or not.

like image 138
John Lehmann Avatar answered Nov 10 '22 17:11

John Lehmann


In your recaptcha div, make sure not to use parenthesis in your data-callback.

Like so data-callback="yourCallback", rather than data-callback="yourCallback();"

like image 12
Qasim Avatar answered Nov 10 '22 16:11

Qasim


The same thing happening with me.I have checked my code carefully, every thing is fine but captcha not shown and in console the message is "ReCAPTCHA couldn't find user-provided function: myCallBack" but finally I found that my JavaScript code was is in page load function. I am just put out it from page load function and its working.

like image 12
Husnain Shabbir Avatar answered Nov 10 '22 18:11

Husnain Shabbir