Search results

Load content through Ajax

Accordion supports to load external contents through AJAX library. Refer the below steps.

  • Import the Ajax module from ej2-base and initialize with URL path.

  • Get data from the Ajax Success event to initialize Accordion with retrieved external path data.

Source
Preview
index.js
index.html
ajax.html
ej.base.enableRipple(true);

var ajax = new ej.base.Ajax('./ajax.html', 'GET', true);
ajax.send().then();
ajax.onSuccess = function (data) {
    var ctn2 = data;
    //Initialize Accordion component
    var accordion = new ej.navigations.Accordion({
        items: [
            { header: 'Department', content: '#acrdnContent1' },
            { header: 'Platform', content: '#acrdnContent2' },
            { header: 'Employee Details', content: ctn2 }
        ]
    });
    //Render initialized Accordion component
    accordion.appendTo('#element');
}
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Accordion</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Toolbar Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element"></div>
        <br><br>
        <div id="result"></div>
        <div id="acrdnContent1" style="display:none">
            <ul style="margin : 0px;padding:0px 16px; list-style-type: none">
                <li>Testing</li>
                <li>Development</li>
            </ul>
        </div>
        <div id="acrdnContent2" style="display:none">
            <ul style="margin : 0px;padding:0px 16px; list-style-type: none">
                <li>Mobile</li>
                <li>Web</li>
            </ul>
        </div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
    ele.style.visibility = "visible";
 }   
        </script>
<script src="index.js" type="text/javascript"></script>
</body></html>
<html><head><script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head><body>&#xFEFF;
<div>
    <div class="comments-list">
        <div class="cont-list">
            <img src="http://js.syncfusion.com/demos/web/content/images/Employee/8.png" alt="contact">
            <br>
            <div>
                <div class="time-panel">1 hr</div>
                <b class="headername">Erik Linden</b></div><br><br> London, one of the most popular tourist 
            destinations in the world for a reason. A cultural and historical hub, London has an excellent public 
            transportation system that allows visitors to see all the fantastic sights without spending a ton 
            of money on a rental car. London contains four World Heritage Sites.
            <div class="comments">
                <div class="c-list">Retweet</div>
                <div class="c-list">Reply</div>
                <div class="c-list">Share</div>
            </div>
        </div>       
    </div>
</div>
<style>
    .cont-list img {
        border-radius: 10px;
        float: left;
        height: 56px;
    }
    
    .comments {
        padding: 10px;
        color: #074B92;
        font-weight: 600;
        position: relative;
        top: 6px;
    }
    
    .cont-list {        
        padding-bottom: 9px;
    }
    
    .cont-list:last-child {
        border-bottom: none;
        padding-bottom: 10px;
    }
    
    .time-panel {
        float: right;
        color: #2382C3;
        margin-right: 10px;
        margin-top: 7px;
    }
    
    .headername {
        font-size: 16px;
        font-weight: 600;
        color: #074B92;
        position: relative;
        left: 9px;
    }
    
    .c-list {
        float: right;
        margin-top: -11px;
        padding-right: 12px;
    }
</style><script>
var ele = document.getElementById('container');
if(ele) {
    ele.style.visibility = "visible";
 }   
        </script>
<script src="index.js" type="text/javascript"></script>
</body></html>