Solved

Javascript load content problem using php

Posted on 2015-01-22
3
178 Views
Last Modified: 2015-01-23
I wish to display products in my table like twitter more tweets load style but here user in my site should click on button to see more products, here I am facing problem when I click on button products loading for first time after next click button not working so I am not getting products, so please help me how to solve this issue

javascript Code is below
$('.more').click(function(){
  var ID = $(this).attr("id");
  var cats = $('input[name=cats]').val();
  $("#more"+ID).html('<img src="<?=ROOT;?>resources/moreajax.gif" />');
  $.post('<?=ROOT;?>product/dataLoad', {id:ID,cats:cats}, function(data){
    if(data) {
      $('ol#updates').append(data);
      $("#more"+ID).remove();
    }
    else{
      $(".morebox").html('The End');// no results
    }
  });
  return false;
});

Open in new window

My Controller Function Code
public function dataLoad(){
        if(isset($_POST['id']))
    {
    $lastmsg=$_POST['id'];
    $str = $_POST['cats'];
    $query=mysql_query("select * from product where id > '".$lastmsg."' AND category_id IN ($str) order by id asc limit 2");
    $numrows = mysql_num_rows($query);
    while($ob = mysql_fetch_array($query))
    {
                $id = $ob['id'];
    ?>
    <a rel="canonical" href="<?=ROOT?><?=$this->user->sluggify($this->user->getCategoryName($ob['category_id']))?>/<?=$ob['url'];?>.html">
    <div class="product cprod" data-id="<?=$ob['id'];?>">
    <strong><h5 class="cube"><?=$ob['name'];?></h5></strong>
    <?php $img = $this->user->getUploadAction($ob['id']); ?>
    <img src="<?=ROOT.'uploads/'.$img?>" data-img="<?=$img?>">
    <p>
    Rs <span><?php
    $price = $this->user->getLowestPrice($ob['id']);
    echo isset($price)?$price:0;
    ?></span>
    </p>
    </div>
    </a>
    <?php
    }//while
    ?>
    
            <div id="more<?php echo $id; ?>" class="morebox" style="clear:both">
    <input type="hidden" name="cats" value="<?=$str;?>" />
    <a href="#" class="more" id="<?=$id;?>">Load More</a>
    </div>
        <?php
                
            }
        }

Open in new window

View Page Code
<ol id="updates">
      <?php
      $str = implode(",",$cats);
      $query = "select * FROM product WHERE category_id IN (".$str.") order by id asc limit 2";
      $result=mysql_query($query);
      $numrows = mysql_num_rows($result);
      while($ob = mysql_fetch_array($result))
      {
            $id = $ob['id']
      ?>
      <a rel="canonical" href="<?=ROOT?><?=$this->user->sluggify($this->user->getCategoryName($ob['category_id']))?>/<?=$ob['url'];?>.html">
      <div class="product cprod" data-id="<?=$ob['id'];?>">
      <strong><h5 class="cube"><?=$ob['name'];?></h5></strong>
      <?php $img = $this->user->getUploadAction($ob['id']); ?>
      <img src="<?=ROOT.'uploads/'.$img?>" data-img="<?=$img?>">
      <p>
            Rs <span><?php
            $price = $this->user->getLowestPrice($ob['id']);
            echo isset($price)?$price:0;
            ?></span>
            </p>
            </div>
      </a>
      <?php
      }
      ?>
      </ol>
            <div id="more<?php echo $id; ?>" class="morebox" style="clear:both">
      <input type="hidden" name="cats" value="<?=$str;?>" />
      <a href="#" class="more" id="<?php echo $id; ?>">Load More</a>
      </div>

Open in new window

0
Comment
Question by:veeru bolem
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
Comment Utility
You want to change

$('.more').click(function(){

to

$("#updates").on("click",".more",function(){

assuming #updates is a parent of the .more objects
0
 

Author Comment

by:veeru bolem
Comment Utility
Oh Great It is working Thank You So Much.
0
 

Author Comment

by:veeru bolem
Comment Utility
I've requested that this question be closed as follows:

Accepted answer: 0 points for veeru bolem's comment #a40566071

for the following reason:

" $("#updates").on("click",".more",function(){ " is solved my problem.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now