Search results

Load content through Ajax in JavaScript Accordion control

08 May 2023 / 1 minute to read

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.
Copied to clipboard
import {Accordion} from '@syncfusion/ej2-navigations';
import { enableRipple } from '@syncfusion/ej2-base';
import { Ajax } from '@syncfusion/ej2-base';


let ajax: Ajax = new Ajax('./ajax.html', 'GET', true);
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 }
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

    <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="//" rel="stylesheet" />
    <script src=""></script>
    <script src="systemjs.config.js"></script>

    <div id='loader'>LOADING....</div>
    <div id='container'>
        <div id='element'></div>
        <div id='result'></div>
        <div id="acrdnContent1" style="display:none">
            <ul style="margin : 0px;padding:0px 16px; list-style-type: none">
        <div id="acrdnContent2" style="display:none">
            <ul style="margin : 0px;padding:0px 16px; list-style-type: none">

Copied to clipboard
    <div class="content">
      <img src="" alt="alice_img" />
      <div id="headername">
      </div><br><br> Alice is a software engineer. He develops the web components. He is passionate about web technologies.