Here my javascript code:
<script type="text/javascript">
var js = document.createElement("script");
js.type = "text/javascript";
js.src = "//mysite.co/js.js";
document.body.appendChild(js);
alert(x);
</script>
In mysitecom/js.js file is like that
var x = '1233123';
//some code
The problem is the alert doesn't work. In google chrome's console says
Uncaught ReferenceError: x is not defined mypage:31 (anonymous function)
But if i include external js file like that;
<script src="//mysite.co/js.js" type="text/javascript" ></script>
It works.
But i need the first method...
What is the fix?
Thanks.