I'm attempting to import an external script into an HTML file. The name of the js file that I want to import is hosted in a SQL database. Therefore, I am using a XMLHttpRequest to access the SQL database so that I can fetch the appropriate name of the script. I then create a script element where I set src equal to 'this.responseText' which should import the name taken from the SQL database. So far so good. My issue is that when I console.log out the script it double wraps the name in qouteationmarks like so:
console:
<script src=""haystack_downtheline""></script>
How do I remove the double quotes so that src="haystack_downtheline".
See below for entire script
HTML file
<script>
function reqListener () {
console.log(this.responseText);
}
var oReq = new XMLHttpRequest(); // New request object
oReq.onload = function() {
console.log(this.responseText);
const js = document.createElement("script");
js.src = this.responseText;
console.log(js);
};
oReq.open("get", "index.php", true);
oReq.send();
</script>