Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting of file into an html page using Javascript?
    primarykey
    data
    text
    <p>I'm currently trying to read text from a file and append it to a element in my html page using the DOM and Javascript. I can't get the text to format though. I've tried using innerHtml but isn't formating at all( no line breaks ).</p> <p>Here is the javascript:</p> <pre><code>http = new XMLHttpRequest(); http.open("GET",FILE,false); http.send(); document.getElementById("tbody").innerHTML = http.responseText </code></pre> <p>Like I said the text gets added to the tbody element but isn't formatted what so ever.</p> <hr> <p>I got it working with this code( with the pre tag ), but like I said it works on my pc but not on the server which doesn't help.</p> <pre><code> http.open("GET",FILE ,false); http.send(); var newtext = document.createTextNode(http.responseText); var para = document.getElementById("tbody"); para.appendChild(newtext); </code></pre> <hr> <p>Here is all my javascript code:</p> <p>function getHTTPObject() { var http = false;</p> <pre><code>/*@cc_on @if (@_jscript_version &gt;= 5) try { http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { http = false; } } @else { http = false; } @end @*/ if (!http &amp;&amp; typeof XMLHttpRequest != 'undefined') { try { http = new XMLHttpRequest(); } catch (e) { http = false; } } return http </code></pre> <p>}</p> <pre><code> function loadData() { http = getHTTPObject(); if (http) { http.open("GET","my file name",false); http.send(); var newtext = document.createTextNode(http.responseText); var para = document.getElementById("tbody"); para.appendChild(newtext); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload