jQuery - run a function from another page

后端 未结 3 1835
死守一世寂寞
死守一世寂寞 2021-01-07 12:50

I have a account page with links that load the pages with the .load. I am wondering how I can get to the load account info page from another page (not from the account page

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-07 13:39

    It sounds like your trying to run a ajax call from ajax inserted content.

    The cool thing about using ajax within jquery is callbacks. plus it super easy to use.

    function loadAccountInformation() {
        $('#accountMain').load("load-account-information.html", function () {
            var ele = $(this);
            ele.find('a').bind('click', function(){
                  ele.load('url');
            })
    
        });
    }
    
    My Information
    

    if thats what your looking for that will work i suggest that you modulize a little more with something like this

    function loadInfo(url){
        $('#accountMain').load(url, function () {
             attachEvents();
        } )
    }
    
    function attachEvents(){
        //Add In selector or selectors that can target ajax links
        $('#linkArea').find('a').unbind('click').bind('click' function(){
           var url = this.href;
    
           loadInfo(url);
    
        })
    
    }
    

提交回复
热议问题