Load a jsp page using AJAX load method

前端 未结 2 1719
栀梦
栀梦 2020-12-15 01:16

Hello everyone I need some help with ajax load method. Basically I need to use Ajax load() to display a jsp within the main page once user checks the radio button. Ive att

2条回答
  •  执念已碎
    2020-12-15 01:52

    Try

    $(function() { // when DOM is ready
        $("#showhidecomment").click(function(){ // when #showhidecomment is clicked
            $("#chkcomments").load("sample.jsp"); // load the sample.jsp page in the #chkcomments element
        }); 
    });
    

    And change your html (the link part) to

    Show Comments

    Since div elements are invalid inside a elements.


    update for comment

    I would add a custom data-url attribute to those elements (to specify the page to load)

    
    
    
    

    and then apply a single handler to them

    $('#verification').on('change','input[type="radio"][data-url]', function(){
        if (this.checked){
            var url = $(this).data('url');
            $("#chkcomments").load( url );
        }
    });
    

提交回复
热议问题