# Carga datos desde una ruta de Total.js con AJAX

> Llama a una ruta de Total.js desde la página con AJAX() y guarda la respuesta en el estado de jComponent.

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: es
Content-SHA256: 641d1368825d3507f9ff085945f82a23f697bb2fb3f7eb4a401eb9494e576e37
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: jcomponent20@3fedd009a277f50fddc608b97afbec553b67c51b
Review: not-recorded

`AJAX('METHOD /url/', [data], callback)` envía una petición y llama al callback con la respuesta. Las respuestas JSON se convierten automáticamente. Combínalo con `SET()` y cualquier `ui-bind` o componente enlazado a esa ruta de estado se actualiza solo.

```js controllers/api.js
exports.install = function() {
	ROUTE('GET /api/hello/', hello);
};

function hello($) {
	$.json({ message: 'Hello from Total.js' });
}
```

```html public/index.html
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>jComponent</title>
	<link rel="stylesheet" href="//cdn.componentator.com/spa.min@20.css" />
	<script src="//cdn.componentator.com/spa.min@20.js"></script>
</head>
<body>

	<p><ui-bind path="greeting" config="text:value">Loading...</ui-bind></p>

	<script>
		AJAX('GET /api/hello/', function(response) {
			SET('greeting', response.message);
		});
	</script>

</body>
</html>
```
