user4038382
user4038382

Reputation:

jQuery load() method

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

Upvotes: 0

Views: 113

Answers (3)

Kelvin Kehinde Omolumo
Kelvin Kehinde Omolumo

Reputation: 197

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});
    });
});

Upvotes: 0

Khushboo
Khushboo

Reputation: 1817

Try below :-

$(".like-div").load("remove.php?keyword=delete&trackid="+track, function( response) {

});

Upvotes: 0

Ashutosh
Ashutosh

Reputation: 324

I think its because $res_code is used before its defined. Move the following code block before the line var track = <?php echo $res_code; ?> ;:

 <?php
     $res_code = '6754567435';
 ?>

Upvotes: 1

Related Questions