doukefu1361 2014-09-30 11:21
浏览 40
已采纳

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

<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>
    <?php
$res_code = '6754567435';
?>
<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'];

echo $trackid;

?>

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

  • 写回答

3条回答 默认 最新

  • dovt85093 2014-09-30 11:54
    关注

    The syntax for the .load is incorrect. .load() is a short form for .post(). the parameters to be passed should be from the post request. Change your code to this:

    $(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});
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效