Load content through post in EJ2 TypeScript Accordion control
17 Dec 20245 minutes to read
Accordion supports to load external contents through AJAX
library. Refer the below steps.
-
Import the
Ajax
module fromej2-base
and initialize with URL path. -
Get data from the Ajax Success event to initialize Accordion with retrieved external path data.
import {Accordion} from '@syncfusion/ej2-navigations';
import { enableRipple } from '@syncfusion/ej2-base';
import { Ajax } from '@syncfusion/ej2-base';
enableRipple(true);
let ajax: Ajax = new Ajax('./ajax.html', 'GET', true);
ajax.send().then();
ajax.onSuccess = (data: string): void => {
let ctn2: string = data;
let accordion: Accordion = new Accordion({
items: [
{ header: 'Department', content: '#acrdnContent1' },
{ header: 'Platform', content: '#acrdnContent2' },
{ header: 'Employee Details', content: ctn2 }
]
});
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="https://cdn.syncfusion.com/ej2/28.1.33/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>LOADING....</div>
<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>
</body>
</html>
<html><head><script src="https://cdn.syncfusion.com/ej2/28.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head><body><div>
<div class="content">
<img src="https://ej2.syncfusion.com/demos/src/schedule/images/alice.png" alt="alice_img">
<br>
<div id="headername">
<b>Alice</b>
</div><br><br> Alice is a software engineer. He develops the web components. He is passionate about web technologies.
</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>