Jump to content


Photo

live is not a function


Best Answer bravo14, 20 October 2013 - 03:25 PM

Thanks guys, changed it to .on and it works a treat Go to the full post


  • Please log in to reply
6 replies to this topic

#1 bravo14

bravo14

    Advanced Member

  • Members
  • PipPipPip
  • 231 posts

Posted 20 October 2013 - 09:59 AM

Hi Guys

 

I have the following page

 

<script src="js/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(function() {



$('.load_more').live("click",function() {


var last_msg_id = $(this).attr("id");



if(last_msg_id!='end'){
    
  $.ajax({
type: "POST",
url: "facebook_style_ajax_more.php",
data: "lastmsg="+ last_msg_id,
beforeSend:  function() {
$('a.load_more').append('<img src="facebook_style_loader.gif" />');
 
},
success: function(html){
    $(".facebook_style").remove();
$("ol#updates").append(html);


}
});
 
}


 
 
 



return false;


});
});

</script>

 

This ajax is called when a user clicks a link similar to facebook's Show Older Posts code is below

 

<ol class="row" id="updates">
    <?php
$query ="select * from `tbl_news` ORDER BY `news_date` desc LIMIT 9";
$result = mysql_query($query);
while($row=mysql_fetch_assoc($result))
{
$msg_id=$row['id'];
$message=$row['headline'];
?>
    <li> <?php echo $message; ?> </li>
    <?php } ?>
  </ol>

 
 
  <div class="facebook_style" id="facebook_style">
  <a id="<?php echo $msg_id; ?>" href="#" class="load_more" >Show Older Posts <img src="img/arrow.png" /> </a>
  </div>

 

When I am clicking on the link I am getting the following error showing in Firebug

 

TypeError: $(...).live is not a function
 

$('.load_more').live("click",function() {

 

Where am I goign wrong, I have used th tutorial and source code from the followign page

 

http://youhack.me/20...-twitter-style/

 



#2 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,570 posts
  • LocationBonita, FL

Posted 20 October 2013 - 11:44 AM

You're probably not using the proper version of jQuery. If you check the documentation you can see that the live method was removed in 1.9, so you'd either need to use an older version or update your code to be compatible with the newer versions.
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#3 bravo14

bravo14

    Advanced Member

  • Members
  • PipPipPip
  • 231 posts

Posted 20 October 2013 - 12:31 PM

Thabks for the reply am I right in saying after looking that on has replaced live?

#4 alpine

alpine

    Advanced Member

  • Members
  • PipPipPip
  • 756 posts
  • LocationNorway

Posted 20 October 2013 - 01:39 PM

Yes, use on instead of live

$('.load_more').on("click",function(){

}


#5 Irate

Irate

    Advanced Member

  • Members
  • PipPipPip
  • 358 posts
  • LocationHamburg, Germany
  • Age:17

Posted 20 October 2013 - 02:34 PM

You can also use bind, too, which accepts any amount of event binders as space-separated list, "mouseenter mouseleave" for example (which would equal hover, anyway).
Quod placet mihi non placeat tibi. - What I think to be good must not always equal your perception of it.

I am not perfect. I try a lot with the code I provide and I don't guarantee for it to work as I have mostly no option to test it on my mobile phone. I do apologize for any inconvenience I caused, but if I do happen to have helped, liking my posts or marking them as to have solved or answered your question would be nice.

#6 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,570 posts
  • LocationBonita, FL

Posted 20 October 2013 - 03:02 PM

You can also use bind, too, which accepts any amount of event binders as space-separated list, "mouseenter mouseleave" for example (which would equal hover, anyway).


.on accepts space-separated event list as well. .bind is also not recommended (use .on instead) but has not been removed as of yet.
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#7 bravo14

bravo14

    Advanced Member

  • Members
  • PipPipPip
  • 231 posts

Posted 20 October 2013 - 03:25 PM   Best Answer

Thanks guys, changed it to .on and it works a treat




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com