0

I've been looking around at various solutions, and the 'easiest' I've found so far appears to be on this comment on a similar question.

I have very little knowledge of javascript or how to implement it, so I'm stuck as to why this might not be working.

So far I have:

<!DOCTYPE html>
<html>
<title>Goal, Strategy, Tactic</title>

<script type="text/javascript">
function read(textFile){
    var xhr=new XMLHttpRequest;
    xhr.open('GET',textFile);
    xhr.onload=show;
    xhr.send()
}

function show(){
    var pre=document.createElement('pre');
    pre.textContent=this.response;
    document.body.appendChild(pre)
}

</script>

and in the body:

<script type="text/javascript">
<!--
read('Android_String_Update.txt');
show();
//-->
</script>

Android_String_Update.txt being a text file with content. I'm also testing this out on safari 8.0 which supports xhr2

Text file content is:

Example of text in file is

#### Inputs
No inputs required

#### Tools
* Jenkins
* Gitlab

#### Steps
1. Navigate to the jenkins
1. Click on "Build Now"

Any ideas what I'm doing wrong?

1 Answer 1

1

I've just tested your code on last version of Firefox, it works perfectly. The tested code :

<!DOCTYPE html>
<html>
<title>Goal, Strategy, Tactic</title>

<script type="text/javascript">
function read(textFile){
    var xhr=new XMLHttpRequest;
    xhr.open('GET',textFile);
    xhr.onload=show;
    xhr.send()
}

function show(){
    var pre=document.createElement('pre');
    pre.textContent=this.response;
    document.body.appendChild(pre)
}

</script>

<body>

<script type="text/javascript">
read('Android_String_Update.txt');
show();
</script>

</body>

</html>

Assuming you have a text file named Android_String_Update.txt in the same folder, it should work. Do you have any errors in javascript console ?

Sign up to request clarification or add additional context in comments.

3 Comments

Ok I see the problem. I'm using this in conjunction with strapdownjs.com. All markdown has to be inside <xmp></xmp> tags, and when I'm passing the txt file contents (more markdown) they don't get rendered at all
Essentially, I'm trying to get a markdown file, file A, to render correctly and to include markdown from file B.
what type of content do you have in your txt file ? post an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.