---
title: "jQuery Timeline Events from Remote API Example | Mobiscroll"
component: "Timeline"
framework: "jQuery"
library_version: "6.2.0"
url: "https://demo.mobiscroll.com/jquery/timeline/load-events-from-remote-api"
---

# Events from Remote API - jQuery Timeline demo

Populate the jQuery Timeline with events fetched from a remote API — pass a data array and keep events in sync.

- [Live demo](https://demo.mobiscroll.com/jquery/timeline/load-events-from-remote-api)
- [View code on GitHub](https://github.com/acidb/mobiscroll-demos-jquery/tree/main/src/demos/eventcalendar/timeline/load-events-from-remote-api)
- This demo in other frameworks: [JavaScript](https://demo.mobiscroll.com/timeline/load-events-from-remote-api.md), [Angular](https://demo.mobiscroll.com/angular/timeline/load-events-from-remote-api.md), [React](https://demo.mobiscroll.com/react/timeline/load-events-from-remote-api.md), [Vue](https://demo.mobiscroll.com/vue/timeline/load-events-from-remote-api.md)

## Description

The timeline can be populated by passing an array to the [`data`](https://mobiscroll.com/docs/jquery/eventcalendar/api#opt-data) option, that you can construct either inline or by getting it from a remote API. The important thing to remember is that events need to be [in a format that the timeline understands](https://demo.mobiscroll.com/jquery/timeline/event-data-structure).

**Interested in load on demand?** [Dynamically load events on month change →](https://demo.mobiscroll.com/jquery/timeline/load-events-on-demand)

## What this demo shows

- A desktop daily timeline where hours are arranged horizontally and resources arranged vertically on the left.
- **Header navigation** The month and year label opens date navigation, while the previous and next arrows move between days and the Today button returns to the current date.
- **Day view** The strip below the header shows the selected days, with the current date highlighted. The timeline displays hourly columns from 12 AM to 12 PM.
- **Resources** Multiple resources are shown as separate timeline rows.
- **Current time** A vertical blue line with a time label marks the current time.
- **Hover behavior** Hovering over the time grid shows a time indicator that follows the cursor in 15-minute increments.
- **Event cards** Events appear as colored cards with a colored stripe on the left, the event title in bold, and the exact start and end time displayed below the title.
- **Date positioning** Events are positioned by their assigned resource and exact date range.
- **Event interaction** Events highlight on hover and show drag and resize handles for repositioning or changing duration.
- **Event selection** Clicking an event selects and highlights it.
- **Event creation** New events can be created by double-clicking the timeline or by clicking and dragging across a time range.
- **Scrolling** The timeline supports horizontal and vertical scrolling for navigating through time and resources.

## Best for

- **Remote event loading examples** Showing how to fetch events from an API and pass them to the timeline view.

## API used in this demo

- [`theme`](https://mobiscroll.com/docs/jquery/eventcalendar/api#opt-theme) - option
- [`themeVariant`](https://mobiscroll.com/docs/jquery/eventcalendar/api#opt-themeVariant) - option
- [`view`](https://mobiscroll.com/docs/jquery/eventcalendar/api#opt-view) - option
- [`resources`](https://mobiscroll.com/docs/jquery/eventcalendar/api#opt-resources) - option
- [`setEvents`](https://mobiscroll.com/docs/jquery/eventcalendar/api#method-setEvents) - method

## Code

### JS

```js
mobiscroll.setOptions({
  theme: 'ios',
  themeVariant: 'light'
});

$(function () {
  var inst = $('#demo-remote-api')
    .mobiscroll()
    .eventcalendar({
      view: {
        timeline: { type: 'day' },
      },
      resources: [
        {
          id: 1,
          name: 'Ryan',
          color: '#fdf500',
        },
        {
          id: 2,
          name: 'Kate',
          color: '#ff4600',
        },
        {
          id: 3,
          name: 'John',
          color: '#ff0101',
        },
        {
          id: 4,
          name: 'Mark',
          color: '#239a21',
        },
        {
          id: 5,
          name: 'Sharon',
          color: '#8f1ed6',
        },
        {
          id: 6,
          name: 'Ashley',
          color: '#01adff',
        },
      ],
    })
    .mobiscroll('getInst');

  $.getJSON('https://trial.mobiscroll.com/timeline-events/?callback=?', function (events) {
    inst.setEvents(events);
  });
});
```

### HTML

```html
<div id="demo-remote-api"></div>
```

## Implementation notes

- Use `timeline: { type: 'day' }` - a single-day view.
- Define 6 named resources: Ryan (yellow `#fdf500`), Kate (orange `#ff4600`), John (red `#ff0101`), Mark (green `#239a21`), Sharon (purple `#8f1ed6`), Ashley (blue `#01adff`).
- On mount, fetch events from `https://trial.mobiscroll.com/timeline-events/` via JSONP using `getJson(url, callback, 'jsonp')`. In the callback, pass the returned array to the calendar - call `inst.setEvents(events)` for the imperative API.

## Run it in your project

1. If not signed up yet, or don't own a license, you can [start a free trial](https://mobiscroll.com/starttrial).

2. Clone the repository:

   ```
   git clone https://github.com/acidb/mobiscroll-demos-jquery.git
   ```

3. If not installed yet, install the Mobiscroll CLI from NPM:

   ```
   npm install -g @mobiscroll/cli
   ```

4. Config Mobiscroll - open a terminal window in the root directory and run:

   ```
   mobiscroll config jquery
   ```

5. Install dependencies - open a terminal window in the root directory and run:

   ```
   npm install
   ```

6. Run the project:

   ```
   npm run dev
   ```

On a trial, add `--trial` to the config command: `mobiscroll config jquery --trial`.

Running a demo locally requires a Mobiscroll trial or a license; setup is per framework at https://mobiscroll.com/docs/jquery/getting-started/installation

## Related demos

- Previous: [Load Inline Events](https://demo.mobiscroll.com/jquery/timeline/load-inline-data.md) - Add events to a jQuery Timeline by passing an inline event array — see how the event object is structured.
- Next: [Load Events on Demand](https://demo.mobiscroll.com/jquery/timeline/load-events-on-demand.md) - Load timeline events on demand — fetch only the visible time range from a remote or local source using the jQuery Timeline.
