0

I'am using Yii framework, I want to reload this div:

<div class="likes" id="likes">
   <?php
      echo $model->likes." ".CHtml::imageButton($src.'like.png', array('value'=>'like',      'width'=>'25px', 'height'=>'20px'));
   ?>
</div>

by using this ajax function that is written in a js file in the extensions folder:

$(document).ready(function(){
   $("#like").click(function(){
      $("#likes").html("result reloaded successfully");
   });
    });

but their is nothing happened when I clicked the button, can you help me?

2
  • Is there an actual AJAX call that you're leaving out for brevity? The code you posted will not make an AJAX request. AJAX aside, to update your div with "result reloaded successfully" you need to change $("#likes") to either $(".likes") to update all divs with the class 'likes' or just $(this) to update only the div that was clicked. Commented Nov 15, 2013 at 13:44
  • Does this answer your question? Onclick reload the div only Commented Jul 8, 2020 at 11:39

3 Answers 3

4

this may help someone

$("#reload").click(function(){

$("#like").load(location.href + " #like>*", "");

});

without page refreshing refresh particular div or any tag

Sign up to request clarification or add additional context in comments.

Comments

1

Create a new file called reload_likes.php with the following code:

<?php
      echo $model->likes." ".CHtml::imageButton($src.'like.png', array('value'=>'like',      'width'=>'25px', 'height'=>'20px'));
?>

then on your javascript file put:

function FreloadDiv(){
    var request = new XMLHttpRequest();
    request.open('GET', 'http://yourdomain.com/reload_likes.php', false);
    request.send(null);
    if (request.status === 200) {
         document.getElementById('likes').innerHTML = request.responseText;
    }
}

Finally add onClick='FreloadDiv();' to your button

3 Comments

their is nothing happened :(
Upload what you did to pastebin or something like that. Did you change the ajax URL, didn't you?
of course I changed it, but their was an error in url, now its done, but all of these solutions aren't solve my problem, I want to make the like button is unclickable and to reload the number of likes after clicking the like button.
0

because you call by the wrong way I think. your id is likes and you are writing like instead of likes. Check it first after that I will check next coming error..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.