0

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?

4

2 回答 2

2

Do you not want:

$('a').on('click', function() {
  $.get('details.txt', function(data) {
    $('#AJAXtest').html(data);
  });
  return false;
});

then

<a href="#">Link</a>

?

于 2012-10-12T11:52:15.760 回答
0

I had put the text file in the wrong folder. I should have looked at the console. Sorry to bother you guys.

于 2012-10-12T11:59:00.890 回答