weixin_33675507 2012-10-12 11:50 采纳率: 0%
浏览 67

jQuery AJAX $ get不起作用

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?

  • 写回答

2条回答 默认 最新

  • DragonWar% 2012-10-12 11:52
    关注

    Do you not want:

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

    then

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

    ?

    评论

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services