Reputation: 7737
This is my first attempt at AJAX, and so I'm keeping it simple. I've got a text file details.txt in the same folder as the index.html page.
The javascript I've got is as follows:
<script language="JavaScript" type="text/javascript">
function getInfoFromServer() {
$.get('details.txt', function(data) {
$('#AJAXtest').html(data);
});
}
</script>
And I'm calling that from a link as follows:
<a href="#" onClick="return false" onmousedown="javascript:getInfoFromServer()">Link</a>
And there's a div sitting nearby:
<div id="AJAXtest"></div>
The content of details.txt are:
test
I can't get this simple thing to work. Can anyone tell me what I'm doing wrong?
Upvotes: 0
Views: 3811
Reputation: 10713
Do you not want:
$('a').on('click', function() {
$.get('details.txt', function(data) {
$('#AJAXtest').html(data);
});
return false;
});
then
<a href="#">Link</a>
?
Upvotes: 2
Reputation: 7737
I had put the text file in the wrong folder. I should have looked at the console. Sorry to bother you guys.
Upvotes: 0