How to code one jquery function for all AJAX links

前端 未结 4 960
生来不讨喜
生来不讨喜 2020-12-11 08:25

I am using zend framework on windows. I want to implement ajax in my project first time. I searched for help and created a very simple ajax functionality.

In

4条回答
  •  我在风中等你
    2020-12-11 09:16

    for simple loading of data in divs i would use the load method

    HTML

    
    
    
    One
    Two
    

    one.phtml content comes here
    two.phtml content comes here

    JS

    jQuery(document).ready(function(){
        jQuery('.ajax').click(function(event){
           event.preventDefault();
    
           var target = '#' + jQuery(this).attr('rel');
           var href = jQuery(this).attr('href');
           jQuery( target ).load( href );
    
          });
    });
    

    Use a single class to identify all links that should use ajax calls instead of their normal use. And add a rel attribute to those links that will contain the id of the container div..

提交回复
热议问题