dongtuan1980 2014-10-05 16:15
浏览 110
已采纳

jQuery load()方法不起作用

Hi I am printing the ajax html response to div element like-div but the ajax html response is not working.

index.php

  <?php
$res_code = '6754567435';
?>
<html>
<head>
    <style type="text/css">
ul.social-icon > li {
    float: left;
    list-style: none;
    padding: 0 15px;
}
    </style>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('ul.social-icon li a.like').click(function()
    { 
        var track = <?php echo $res_code; ?> ;
        $(".like-div").load("remove.php?keyword=delete&trackid="+track);
    });
});
</script>
</head>
<body>

<ul class="social-icon">
              <li><a class="like" href="#123">Like</a></li>
</ul>

<div class="like-div"></div>
</body>
</html> 

I want to diaply the ajax response in div like-div on clicking the hyperlink Like but this is not showing anything in the div trait.

remove.php

   <?php
    $keyword = $_REQUEST['keyword'];
    $trackid = $_REQUEST['trackid'];

    if($trackid != '')
{
    echo "hello";
}
    ?>

remove.php is the page from where response will come on sending the request. what could be the reason that it is not showing the response in div?

Please help me to fix this. Thanks

  • 写回答

1条回答 默认 最新

  • douchuilai2355 2014-10-05 16:23
    关注

    You need to cancel the click

    $('ul.social-icon li a.like').click(function(e) {
      e.preventDefault(); 
    

    Also I would do

    $(function(){
      $('ul.social-icon li a.like').click(function(e) { 
        e.preventDefault(); 
        $(".like-div").load("remove.php?keyword=delete&trackid=<?php echo $res_code; ?>");
      });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵