[英]How to access a var inside an API script [Next JS / React JS]
I'm trying to enable a success message after the form is complete using Mailerlite script.我正在尝试使用 Mailerlite 脚本在表单完成后启用成功消息。
How can I access variables inside a script to be able to show the success message?如何访问脚本中的变量以显示成功消息?
ml_webform_success_983964()
this function works with onClick although it won't validate the field and just show the message. ml_webform_success_983964()
这个 function 与 onClick 一起使用,尽管它不会验证该字段而只显示消息。 So maybe I need to access the script
.所以也许我需要访问
script
。
Someone, please help me I have no idea what I'm doing lol有人,请帮助我,我不知道我在做什么哈哈
useEffect(() => {
const script = document.createElement("script");
script.src =
"https://groot.mailerlite.com/js/w/webforms.min.js?vaa2c3c2aced59c19bcfc4be08835b7b3";
script.async = true;
document.body.appendChild(script);
return () => {
document.body.removeChild(script);
};
}, []);
function ml_webform_success_983964() {
var $ = ml_jQuery || jQuery;
$(".ml-subscribe-form-983964 .row-success").show();
$(".ml-subscribe-form-983964 .row-form").hide();
}
I think you should use ml_webform_success_983964()
function.我认为您应该使用
ml_webform_success_983964()
function。
For me, I append a script at the end of the page and the body of script was something like that:对我来说,我在页面末尾 append 一个脚本,脚本的主体是这样的:
function ml_webform_success_983964() {
console.log("success")
}
and remove onClick={ml_webform_success_983964}
in Register button because success will be handled by mailerlite script so this function should only run when submit is success.并删除注册按钮中的
onClick={ml_webform_success_983964}
因为成功将由 mailerlite 脚本处理,所以这个 function 应该只在提交成功时运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.