2013-12-01 5 views
0

У меня есть большая проблема с этой функцией:Вызов функции в .js файле

(function($) { 

    $.fn.scrollPagination = function(options) { 
function getData() { 
       $.post('load.php', { 
        action: 'scrollpagination', 
        number: $settings.nop, 
        offset: offset, 
       }, function(data) { 

        // Change loading bar content (it may have been altered) 
        $this.find('.loading-bar').html($initmessage); 

        // If there is no data returned, there are no more posts to be shown. Show error 
        if (data == "") { 
         $this.find('.loading-bar').html('<span class="label label-info">No News</span>'); 
        } 
        else { 

         // Offset increases 
         offset = offset + $settings.nop; 

         // Append the data to the content div 
         $this.find('.content').append(data); 

         // No longer busy! 
         busy = false; 
        } 

       }); 

      } 

      getData(); // Run function initially 
    }); 
    } 

})(jQuery); 

(От: http://www.inserthtml.com/2013/01/scroll-pagination/)

Я буду называть функции «GetData» в другой файл HTML.

$(document).ready(function() { 
        $('#statustext').submit(function() { 
         .... 
         }) 
           .done(function(data) { 
            getData(); 
           }) 
           .fail(function() { 
            ... 
           }); 
         return false; 
        }); 
       }); 

Но, не работает. Могут ли все помочь мне? Я искал в Stackoverflow и Google, но я ничего не нашел.

+0

try .scrollPagination.getData() –

+0

Не работает. .scrollPagination.getData() или scrollPagination.getData() – LosAngeles

+3

Это не входит в область действия, поэтому он недоступен извне плагина. – adeneo

ответ

0

(функция ($) {

$.fn.scrollPagination = function(options) { 

    var settings = { 
     nop  : 10, // The number of posts per scroll to be loaded 
     offset : 0, // Initial offset, begins at 0 in this case 
     error : '', // When the user reaches the end this is the message that is 
            // displayed. You can change this if you want. 
     delay : 500, // When you scroll down the posts will load after a delayed amount of time. 
         // This is mainly for usability concerns. You can alter this as you see fit 
     scroll : true // The main bit, if set to false posts will not load as the user scrolls. 
         // but will still load if the user clicks. 
    } 

    // Extend the options so they work with the plugin 
    if(options) { 
     $.extend(settings, options); 
    } 

    // For each so that we keep chainability. 
    return this.each(function() {  

     // Some variables 
     $this = $(this); 
     $settings = settings; 
     var offset = $settings.offset; 
     var busy = false; // Checks if the scroll action is happening 
          // so we don't run it multiple times 

     // Custom messages based on settings 
     if($settings.scroll == true) $initmessage = ''; 
     else $initmessage = ''; 

     // Append custom messages and extra UI 
     $this.append('<div class="content"></div><div class="loading-bar">'+$initmessage+'</div>'); 

     function getData() { 

         $("#loader").fadeIn(400).html('<img src="http://zingclub.in/images/loading.gif" align="absmiddle">&nbsp;Loading Images'); 


      // Post data to ajax.php 
      $.post('ajax.php', { 
       category :$('#category').val(), 
       category1:$('#category1').val(), 
       subcat:$('#subcat').val(), 
       area:$('#filter_area1').val(), 
       action  : 'scrollpagination', 
       number  : $settings.nop, 
       offset  : offset, 

      }, function(data) { 

       // Change loading bar content (it may have been altered) 
       $this.find('.loading-bar').html($initmessage); 


       // If there is no data returned, there are no more posts to be shown. Show error 
       if($('#filter_area1').val()!='empty') 
        { 

          $this.find('.content').html(''); 

          $this.find('.content').html(data); 


        } 
       else if(data == "") { 
        $this.find('.loading-bar').html($settings.error); 
       } 
       else { 

        // Offset increases 
        offset = offset+$settings.nop; 

        // Append the data to the content div 
        $this.find('.content').append(data); 

        // No longer busy! 
        busy = false; 

       } 

      }); 

     } 

     if($('#filter_area1').val()!='empty') 

        { 
         var a= $('#filter_area1'); 
          $this.find('.content').hide.html(data)(); 
          $a.append(data).append($loader.hide()); 
        } 
        else 
        { 
     getData(); // Run function initially 
        } 

     // If scrolling is enabled 
     if($settings.scroll == true) { 
      // .. and the user is scrolling 
      $(window).scroll(function() { 

       // Check the user is at the bottom of the element 
       if($(window).scrollTop() + $(window).height() > $this.height() && !busy) { 

        // Now we are working, so busy is true 
        busy = true; 

        // Tell the user we're loading posts 
        $this.find('.loading-bar').html(''); 

        // Run the function to fetch the data inside a delay 
        // This is useful if you have content in a footer you 
        // want the user to see. 
        setTimeout(function() { 

         getData(); 

        }, $settings.delay); 

       } 
      }); 
     } 

     // Also content can be loaded by clicking the loading bar/ 
     $this.find('.loading-bar').click(function() { 

      if(busy == false) { 
       busy = true; 
       getData(); 
      } 

     }); 

    }); 
} 

}) (Jquery);

+0

Используйте этот код. I ваш файл сценария java и в вашем php-файле используйте один div для загрузки. – user3198563

Смежные вопросы