0

I'm trying to use pagination script. But I use jQuery ver. 1.9.1 on website, and this script works just with version 1.8.3... I'm new to jQuery, and I don't know how to fix it. I think, there is some syntax problem with ajax and ParseInt...

jsFiddle EXAMPLE

Original script

jQuery

  $(document).ready(function(){
          function loading_show(){
              $('#loading').html("<img src='images/loading.gif'/>").fadeIn('fast');
          }
          function loading_hide(){
              $('#loading').fadeOut('fast');
          }                
          function loadData(page){
              loading_show();                    
              $.ajax
              ({
                  type: "POST",
                  url: "load_data.php",
                  data: "page="+page,
                  success: function(msg)
                  {
                      $("#container").ajaxComplete(function(event, request, settings)
                      {
                          loading_hide();
                          $("#container").html(msg);
                      });
                  }
              });
          }
          loadData(1);  // For first time page load default results
          $('#container .pagination li.active').live('click',function(){
              var page = $(this).attr('p');
              loadData(page);

          });           
          $('#go_btn').live('click',function(){
              var page = parseInt($('.goto').val());
              var no_of_pages = parseInt($('.total').attr('a'));
              if(page != 0 && page <= no_of_pages){
                  loadData(page);
              }else{
                  alert('Enter a PAGE between 1 and '+no_of_pages);
                  $('.goto').val("").focus();
                  return false;
              }

          });
      });
Patrik
  • 1,269
  • 7
  • 30
  • 49
  • 1
    You'll need to replace live() with on(), otherwise it looks like the rest of the code should be valid in 1.9.1 ? – adeneo May 08 '13 at 19:42
  • I can not make working example in jsFiddle, but I think there is some other problem with ajax. Becouse this jquery script can not load informations from php script... – Patrik May 08 '13 at 19:51
  • 1
    Why are you doing ajaxComplete inside of an ajax success? – Kevin B May 08 '13 at 20:00
  • I'm new to jQuery. I found this script on some page... But I think, that steps are : start Ajax > show loading animation > on ajaxComplete hide loading animation > show loaded informations. – Patrik May 08 '13 at 20:07

1 Answers1

3

You don't need to fix anything, you can still use the 1.8.3 code with the new version by using the jQuery Migrate plugin. Even in the Fiddle on the left hand side, you have the option to include the Migrate plugin.

Using the plugin is easy; just include it immediately after the script tag for jQuery, for example.

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.1.js"></script>

For more information, see the jQuery Migrate documentation.

palaѕн
  • 72,112
  • 17
  • 116
  • 136
  • Thanx Palash, you are right, it works. But, it is another big script on page. I would like to find some clear solution. :) – Patrik May 08 '13 at 19:57
  • 1
    The file is not that big. The minified version is just 8KB :) – palaѕн May 08 '13 at 20:00
  • Yes it works realy fine... but, maybe there is some solution with a few letter change. :) – Patrik May 08 '13 at 20:11
  • latest v of 1.2.1 can be used but yes its IE support can be a mess :P http://plugins.jquery.com/migrate/ – Milson May 12 '13 at 17:07