title: Ajax pagination with php returning entire page instead of the paginated div
body: <p>I have a php website which has to display list of items on a page in paginated format.I achieved this using php but now I want to add ajax functionality to it.So I added this function to be called on the click of the page no in the paginated portion.
  Ajax/Jquery function:(.paginate is the class for the page links)</p>
  
  <pre><code>$(document).ready(function()
  {
  $('.paginate').live('click', function(e)
  {
      //alert("Here");
      e.preventDefault();
      var btnPage = $(this);
      //alert(btnPage.attr('href'));     /RealEstate/process.php?page=3&amp;ipp=2&amp;venue=Array $('#temp').load($(this).attr("href")+' #temp');
      var getUrl = btnPage.attr('href');
      //var dataLocality = { 'locality[]' : []};
      //alert(getUrl);
      $.ajax(
      {
         url:btnPage.attr('href'),
          success : function(resp)
          {
              // replace current results with new results.
              $('#project_section').html(resp);
          },
          error : function()
          {
              window.location.href = btnPage.attr('href');
          }
      });
   });
  });
  </code></pre>
  
  <p>My paginate function is somewhat like this:</p>
  
  <pre><code>function paginate()
  {
      if(!isset($this-&gt;default_ipp)) $this-&gt;default_ipp='2';
      if($_GET['ipp'] == 'All')
      {
          $this-&gt;num_pages = 1;
  
      }
      else
      {
          if(!is_numeric($this-&gt;items_per_page) OR $this-&gt;items_per_page &lt;= 0) $this-&gt;items_per_page = $this-&gt;default_ipp;
          $this-&gt;num_pages = ceil($this-&gt;items_total/$this-&gt;items_per_page);
      }
      $this-&gt;current_page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1 ; // must be numeric &gt; 0
      $prev_page = $this-&gt;current_page-1;
      $next_page = $this-&gt;current_page+1;
      if($_GET)
      {
          $args = explode("&amp;",$_SERVER['QUERY_STRING']);
          foreach($args as $arg)
          {
              $keyval = explode("=",$arg);
              if($keyval[0] != "page" And $keyval[0] != "ipp") $this-&gt;querystring .= "&amp;" . $arg;
          }
      }
  
      if($_POST)
      {
          foreach($_POST as $key=&gt;$val)
          {
              if($key != "page" And $key != "ipp") $this-&gt;querystring .= "&amp;$key=$val";
          }
      }
      if($this-&gt;num_pages &gt; 4)
      {
          $this-&gt;return = ($this-&gt;current_page &gt; 1 And $this-&gt;items_total &gt;= 10) ? "&lt;a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$prev_page&amp;ipp=$this-&gt;items_per_page$this-&gt;querystring\"&gt;&amp;laquo; Previous&lt;/a&gt; ":"&lt;span class=\"inactive\" href=\"#\"&gt;&amp;laquo; Previous&lt;/span&gt; ";
  
          $this-&gt;start_range = $this-&gt;current_page - floor($this-&gt;mid_range/2);
          $this-&gt;end_range = $this-&gt;current_page + floor($this-&gt;mid_range/2);
  
          if($this-&gt;start_range &lt;= 0)
          {
              $this-&gt;end_range += abs($this-&gt;start_range)+1;
              $this-&gt;start_range = 1;
          }
          if($this-&gt;end_range &gt; $this-&gt;num_pages)
          {
              $this-&gt;start_range -= $this-&gt;end_range-$this-&gt;num_pages;
              $this-&gt;end_range = $this-&gt;num_pages;
          }
          $this-&gt;range = range($this-&gt;start_range,$this-&gt;end_range);
  
          for($i=1;$i&lt;=$this-&gt;num_pages;$i++)
          {
              if($this-&gt;range[0] &gt; 2 And $i == $this-&gt;range[0]) $this-&gt;return .= " ... ";
              // loop through all pages. if first, last, or in range, display
              if($i==1 Or $i==$this-&gt;num_pages Or in_array($i,$this-&gt;range))
              {
                  $this-&gt;return .= ($i == $this-&gt;current_page And $_GET['page'] != 'All') ? "&lt;a title=\"Go to page $i of $this-&gt;num_pages\" class=\"current\" href=\"#\"&gt;$i&lt;/a&gt; ":"&lt;a class=\"paginate\" title=\"Go to page $i of $this-&gt;num_pages\" href=\"$_SERVER[PHP_SELF]?page=$i&amp;ipp=$this-&gt;items_per_page$this-&gt;querystring\"&gt;$i&lt;/a&gt; ";
              }
              if($this-&gt;range[$this-&gt;mid_range-1] &lt; $this-&gt;num_pages-1 And $i == $this-&gt;range[$this-&gt;mid_range-1]) $this-&gt;return .= " ... ";
          }
          $this-&gt;return .= (($this-&gt;current_page &lt; $this-&gt;num_pages And $this-&gt;items_total &gt;= 10) And ($_GET['page'] != 'All') And $this-&gt;current_page &gt; 0) ? "&lt;a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$next_page&amp;ipp=$this-&gt;items_per_page$this-&gt;querystring\"&gt;Next &amp;raquo;&lt;/a&gt;\n":"&lt;span class=\"inactive\" href=\"#\"&gt;&amp;raquo; Next&lt;/span&gt;\n";
          $this-&gt;return .= ($_GET['page'] == 'All') ? "&lt;a class=\"current\" style=\"margin-left:10px\" href=\"#\"&gt;All&lt;/a&gt; \n":"&lt;a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[PHP_SELF]?page=1&amp;ipp=All$this-&gt;querystring\"&gt;All&lt;/a&gt; \n";
      }
      else
      {
          for($i=1;$i&lt;=$this-&gt;num_pages;$i++)
          {
              $this-&gt;return .= ($i == $this-&gt;current_page) ? "&lt;a class=\"current\" href=\"#\"&gt;$i&lt;/a&gt; ":"&lt;a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$i&amp;ipp=$this-&gt;items_per_page$this-&gt;querystring\"&gt;$i&lt;/a&gt; ";
          }
          $this-&gt;return .= "&lt;a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=1&amp;ipp=All$this-&gt;querystring\"&gt;All&lt;/a&gt; \n";
      }
      $this-&gt;low = ($this-&gt;current_page &lt;= 0) ? 0:($this-&gt;current_page-1) * $this-&gt;items_per_page;
      if($this-&gt;current_page &lt;= 0) $this-&gt;items_per_page = 0;
      $this-&gt;limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this-&gt;low,$this-&gt;items_per_page";
  }
  </code></pre>
  
  <p>On the page where I want to display the paginated <strong>div</strong>,i am getting the <strong>entire page</strong> as response instead of the paginated <strong>div</strong>.I have separated the paginated div to a separate page and included it(added code below) on the display page,but not working.</p>
  
  <pre><code>&lt;div id="project_section"&gt;
      &lt;?php include_once("cityPropertySearchResults.php");?&gt;        
  &lt;/div&gt;
  </code></pre>
  
  <p>Can someone throw some light over it?<br/>
  <strong>UPDATED:</strong>
  I found something similar <a href="https://stackoverflow.com/questions/1309197/prevent-entire-php-execution-on-ajax-request?rq=1">here</a></p>
  
  <p>This works for the links but now,all the js files go on loading again and again,recursively.</p>
  
  <p>Thanks for your time.</p>