Я могу скачать MP3, нажав на кнопки, но я хочу отправить параметр напрямую
Мой код:
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code><!DOCTYPE html> <html> <head> <script src="https://code.responsivevoice.org/responsivevoice.js"></script> </head> <script type="text/javascript"> function belalim(self){ document.querySelector('form').onsubmit = function generateAudio(e) { const xhr = new XMLHttpRequest(); xhr.responseType = 'blob'; xhr.onreadystatechange = function () { if (xhr.readyState !== XMLHttpRequest.DONE) { return; } if (xhr.status !== 200) { document.body.innerHTML = this.statusText; return; } document.body.innerHTML = `<a href="${URL.createObjectURL(this.response)}" download="audio.mp3">Download Audio</a>`; }; xhr.open('GET', `https://cors-anywhere.herokuapp.com/https://code.responsivevoice.org/getvoice.php?t="${encodeURIComponent(this.t.value)}"&tl=tr-TR&sv=g1&vn=&pitch=0.5&rate=0.5&vol=1&gender=male`); xhr.send(null); document.body.innerHTML = 'Generating Audio ...'; return false; } }; </script> <form action=""> <input name="t" type="text" placeholder="text" required="required" /> <input type="submit" onclick="belalim();" value="Generate Audio" /> </form>
Я хотел бы отправить параметр следующим образом:
xhr.open('GET', `https://cors-anywhere.herokuapp.com/https://code.responsivevoice.org/getvoice.php?t="${encodeURIComponent("<?php print $_GET['metin'];?>")}"&tl=tr-TR&sv=g1&vn=&pitch=0.5&rate=0.5&vol=1&gender=male`);
, и я хочу загрузить файл без нажатия кнопки. Могу ли я получить совет о том, как начать с этим?