Hi @meredydd,
Thanks for your reminder and introducing the anvil.call(), which is a great feature.
Here is the complete client code, I got issue with the the first argument is a DOM element of the anvil.call(), but managed to get it.
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<div class="g-recaptcha" data-sitekey="your_key" data-callback="get_token"></div>
<script>
function get_token(){
var linkElement = $('.g-recaptcha');
anvil.call(linkElement, "my_method", "World").then(function (r) {
console.log("The function returned:", r);
});
}
</script>
def my_method(self, name):
alert(f"Hello, {name}")
return 42
The server code is quite tricky
def _get_google_response(response):
resp = anvil.http.request(
url=f"https://www.google.com/recaptcha/api/siteverify?secret=your_key&response={response}",
method="POST",
json=True,
)
return resp