Javascript 如何在数据库中将变量传递到index.html
我在我的Javascript 如何在数据库中将变量传递到index.html,javascript,angular,payment-gateway,Javascript,Angular,Payment Gateway,我在我的index.html <script type="text/javascript" src="https://app.sandbox.midtrans.com/snap/snap.js" data-client-key="my-data-client-key"> </script> midtrans的脚本标记没有出现,我得到了core.js:6014错误引用ERROR:snap没有
index.html
<script type="text/javascript" src="https://app.sandbox.midtrans.com/snap/snap.js"
data-client-key="my-data-client-key">
</script>
midtrans的脚本标记没有出现,我得到了core.js:6014错误引用ERROR:snap没有定义
您有两个选择
客户端密钥
没有问题,因为提供商将限制每个域使用客户端密钥等
在您的案例中,文档提到将客户机密钥放在html中
一旦在前端使用密钥,就无法隐藏它。最后,它应该位于页眉标记中或页面上的某个位置,以便完成所需的处理 从他们的角度来看,这是一个客户机密钥,因此没有什么可担心的。此外,Mid Trans还接受商户Url和其他回调Url,通过这些Url限制支付和重定向。假设这些不是他们所说的,那么某人唯一能做的事情就是代表您执行一项支付交易,并将其存入您的帐户
对于Google analytics,你也无能为力,但如果有人得到你的密钥,你收集的数据可能会被污染,因此我建议你在分析页面上创建一个过滤器,并限制只匹配你的域的点击。查看如何做到这一点。是的,我知道了,我正在使用数字1,因此我的朋友只在我的环境中更改了密钥,但它没有显示在我的HTML中。因此,我使用了你的第二个解决方案,仍然没有显示。我已更新了我的答案,我更喜欢使用第一个解决方案,document.write不适合使用该密钥无论如何都将在前端使用,除非有其他原因需要将其存储在环境中,否则它不值得。标题中的所有人都可以看到tagi存储了此应用程序的多个密钥,我的后端正在将此应用程序部署到主机,因此他只在env中更改密钥
if (environment.production) {
enableProdMode();
// HACK: Don't log to console in production environment.
// TODO: This can be done in better way using logger service and logger factory.
if (window) {
window.console.log = window.console.warn = window.console.info = function () {
// Don't log anything.
};
}
document.write('<script type="text/javascript" src="https://app.sandbox.midtrans.com/snap/snap.js" data-client-key="'+environment.midtransKey+'" ></script>');
} else {
document.write('<script type="text/javascript" src="https://app.sandbox.midtrans.com/snap/snap.js" data-client-key="'+environment.midtransKey+'" ></script>');
}
import { environment } from './environments/environment';
const script = document.createElement('script');
script.src = "https://app.sandbox.midtrans.com/snap/snap.js";
if (environment.production) {
script.setAttribute("data-client-key","my-data-client-key")
} else if (environment.staging) {
script.setAttribute("data-client-key","my-data-client-key")
}
document.head.appendChild(script);
var html = document.documentElement.innerHTML
document.documentElement.innerHTML = html.replace("my-data-client-key", environment.variable)