How to display content of javascript source file? I have the url of the source file. I just want to display it in a text area and alert box. No matter the size of the file.
<pre>function getFile() {
var url = "http://example.com/s/js/file.js";
if(window.XMLHttpRequest)
{
//code for IE7+, FF, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
//code for IE5,IE6
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function redraw()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert(xmlhttp.responseText);
}
}
xmlhttp.open("GET",url,false);
xmlhttp.send();
}
</pre>
You can do it like this:
$.get("file.js", function(file) {
$("textarea").val(file);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.