Search code examples
ajaxrendergsp

Rendering a gsp page after an ajax success


I want to render a gsp page inside a fancybox after the ajax call has returned a success.

I have done the following :

   function editCompanyProfile(companyProfileId){
   $.ajax({
       url: '${createLink(controller: 'benefitContract',action: 'editCompanyProfile')}',
       type: 'POST',
       data: {id:companyProfileId},
       success: function (data) {
           $.fancybox({
            /* I need to render a gsp here */
           })
       }
   })

}

     def editCompanyProfile(){
          def isroleAdministrator=false
    if (User.findById(session.userId).allAuthorities?.contains('ROLE_ADMINISTRATOR')){
        isroleAdministrator=true;
    }
    render(template:"/benefitContract/companyProfile",model:[isroleAdministrator:isroleAdministrator,companyProfile:params.id])
}

Could anyone tell me how should i go about doing it?


Solution

  • Why don't you try overriding the div's content instead. It will be less tedious and more immaculate.

    function editCompanyProfile(companyProfileId,groupId){
       $.ajax({
           url: '${createLink(controller: 'benefitContract',action: 'addEditCompanyProfile')}',
           type: 'POST',
           data: {sourceId:companyProfileId,groupId:groupId},
           success: function (data) {
               $('#companyProfile').html(data);
           }
       })
    }