Ejaz
Ejaz

Reputation: 1632

How to display the content from .txt file into a div using jQuery load?

I am not sure where I am going wrong here. I have a div and a button.

On the click of the button, I am trying to display the contents from a .txt file in this div.

HTML:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <div id='abc'>AA</div>
    <button id='bt'>Submit</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>

js:

$('#bt').click(function() {
    $('#abc').load('hello.txt');
})

'hello.txt' file is located in the same folder where .html file is located.

Nothing is displayed and I don't get any error either.

Upvotes: 3

Views: 2169

Answers (1)

Ted
Ted

Reputation: 14937

Are you working locally? It will work, but when testing, you won't get results from a localdrive, you'll need an actual http server. The invisible error is an XMLHttpRequest error.

Upvotes: 5

Related Questions