Doubt of ajax to create a JS page

Asked

Viewed 9 times

0

How do I create a javascript page that contains a button that, when I click, it accesses, via ajax, the contents of a txt file that is saved in the same folder as the page in question, and also displays its data inside a div with id = "data".

Thank you.

  • Welcome to Stackoverflow in Portugal, you might want to make a Tour: https://answall.com/tour or Have a look at Help Center: https://answall.com/help and check how to ask a good question to be answered. You should post what you have tried and also the code you are using. Hardly anyone will do the job for you.

1 answer

0

$.ajax({
			url: 'arquivo.txt',
			success: function(data){
				$('#app').append(data)
			}
		})	
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="app">

So, remembering that if you run it will not work, because you do not have the file in the current directory

Browser other questions tagged

You are not signed in. Login or sign up in order to post.