I'm having an issue invoking the inline javascript inside the mustache template file (.hjs). Full mustache.
when I click "Verify", the script tag and console logs do not run. It is not pulling the input code I type into the input box either.
For context: I am sending the mustache template (html) from my node server to an iFrame on the front end (React). I want the template to interact with the user and send an API call to my server and verify the 2FA.
Short mustache
I am sending variables to the javascript through {{ var }}, which is standard for mustache.
My thoughts: this code works in a regular index.html file.
New beard and moustache styles
any help or tips appreciated! I can try any suggestions locally to debug further.
<!DOCTYPE html> <html> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <body> <div id="inline-widget" > <p Segoe UI','Roboto','Oxygen','Ubuntu','Cantarell','Fira Sans','Droid Sans','Helvetica Neue',sans-serif;color:#48545d;font-size:14px;line-height:125%;margin:10px auto 20px;text-align:center"> Please complete your purchase by entering the 4 character code at the end of your recent charge description. </p> <img src="https://d2xxy1rwbjzckp.cloudfront.net/verification.jpeg" alt="Example"></img> <p Segoe UI','Roboto','Oxygen','Ubuntu','Cantarell','Fira Sans','Droid Sans','Helvetica Neue',sans-serif;color:#48545d;font-size:11px;line-height:125%;margin-bottom:10px auto 20px;text-align:left"> Code = 3122 in this example </p> <p id="error-message" Segoe UI','Roboto','Oxygen','Ubuntu','Cantarell','Fira Sans','Droid Sans','Helvetica Neue',sans-serif;color:#48545d;font-size:11px;line-height:125%;margin-bottom:10px auto 20px;text-align:center;color:red"></p> <div class="input-group mb-3"> <input id="2faCode" type="text" class="form-control" placeholder="4 digit code" aria-describedby="basic-addon2"/> <div class="input-group-append"> <button class="btn btn-outline-secondary" id="verifyButton" type="button">Verify</button> </div> </div> </div> <script> const button = document.getElementById('verifyButton'); button.addEventListener('click', async _ => { try { const verifyCode = document.getElementById('2faCode').value; console.log('start!: ', verifyCode); const response = await fetch({{ callbackUrl }}, { method: 'post', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ orderId: {{ orderId }}, verificationCode: {{ verifyCode }} }) }); const contentType = response.headers.get("content-type"); if (contentType === 'text/html; charset=utf-8') { const textResponse = await response.text(); document.getElementById("inline-widget").innerHTML = textResponse; } else { const parsedResponse = await response.json(); document.getElementById("error-message").innerHTML = parsedResponse.message; } } catch(err) { document.getElementById("error-message").innerHTML = err; console.error(`Error: ${err}`); } }); </script> </body> </html>
Men's beard and moustache styles
Comments
There are no comments for this post "jquery - inline javascript callback onclick using mustache templating - Stack Overflow". Be the first to comment...
Add Comment