Ember CLI IC Ajax
The `ember-cli-ic-ajax` package is an Ember CLI addon designed to integrate the `ic-ajax` library into an Ember.js application, making its functionality available within the `vendor.js` build output. `ic-ajax` itself serves as an Ember-friendly wrapper around jQuery's `$.ajax` method, primarily created to provide RSVP promises for asynchronous operations and to simplify AJAX testing through fixture support. This package represents an approach to AJAX management prevalent in earlier Ember ecosystems, preceding the widespread adoption of native `fetch` API or the official `ember-ajax` service (which is now also deprecated in favor of `ember-fetch`). The current stable version, 1.0.0, was released approximately 10 years ago, and both `ember-cli-ic-ajax` and its underlying `ic-ajax` library are no longer actively maintained. Developers should consider modern alternatives like `ember-fetch` for new projects or migrating existing ones, as this package is effectively abandoned.
Common errors
-
Uncaught ReferenceError: jQuery is not defined
cause `ic-ajax` is a wrapper around jQuery's `$.ajax` method, and this error indicates jQuery is not loaded or available in the global scope.fixEnsure jQuery is correctly included in your Ember application's build process. In modern Ember CLI, this typically involves ensuring `ember-cli-jquery` or similar is installed and configured, or explicitly importing `jquery` if tree-shaken. -
Error: Could not find module `ic-ajax` imported from `(unknown entry)`
cause This error occurs when the `ic-ajax` module cannot be resolved by Ember CLI's module loader, often due to improper installation, a missing `app.import` statement for older addons, or attempting to import a globally exposed library as a module.fixVerify that `ember-cli-ic-ajax` is installed correctly via `npm install --save-dev ember-cli-ic-ajax`. If using an older Ember CLI setup, check `ember-cli-build.js` for `app.import('bower_components/ic-ajax/dist/named-amd/main.js', { exports: { 'ic-ajax': ['default', 'request', 'raw', 'defineFixture', 'lookupFixture'] } });` or similar configuration if not handled automatically by the addon blueprint.
Warnings
- breaking The `ember-cli-ic-ajax` addon and its underlying `ic-ajax` library are abandoned and have not been updated for approximately 10 years. They are incompatible with modern Ember.js features, best practices, and JavaScript ecosystems.
- gotcha Relies on jQuery for its AJAX implementation. Modern Ember applications increasingly reduce their reliance on jQuery. If jQuery is not available or is removed, `ic-ajax` will fail.
- gotcha `ic-ajax` (and by extension `ember-cli-ic-ajax`) is incompatible with Ember's FastBoot server-side rendering, as it directly uses browser-specific jQuery `$.ajax` methods.
- deprecated The primary `ember-ajax` addon, which was a successor to `ic-ajax`, is also now deprecated in favor of `ember-fetch` or `ember-ajax-fetch`.
Install
-
npm install ember-cli-ic-ajax -
yarn add ember-cli-ic-ajax -
pnpm add ember-cli-ic-ajax
Imports
- request
const request = require('ic-ajax').request;import { request } from 'ic-ajax'; - ajax
const ajax = require('ic-ajax');import ajax from 'ic-ajax';
- ic.ajax
import { ic.ajax } from 'ic-ajax';const { request } = window.ic.ajax; // or Ember.$.ajax for jQuery compatibility
Quickstart
import Component from '@ember/component';
import { action } from '@ember/object';
import { request } from 'ic-ajax';
export default class DataFetcherComponent extends Component {
message = 'Click button to fetch data';
data = null;
@action
async fetchData() {
this.set('message', 'Fetching data...');
try {
const response = await request('/api/data', {
method: 'GET',
dataType: 'json'
});
this.set('data', response);
this.set('message', 'Data fetched successfully!');
} catch (error) {
console.error('AJAX Error:', error);
this.set('message', `Failed to fetch data: ${error.message || error.statusText}`);
}
}
}