?
Solved

Javascript load content problem using php

Posted on 2015-01-22
3
Medium Priority
?
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 40565941
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
ID: 40566071
Oh Great It is working Thank You So Much.
0
 

Author Comment

by:veeru bolem
ID: 40566076
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

765 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