# Carregar dados de uma rota Total.js com AJAX

> Chame uma rota Total.js a partir da página com AJAX() e ponha a resposta no estado do jComponent.

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: pt
Content-SHA256: 8ca5acc1ad656b6521f9f7e145c8b9335aba291975f8e87c6109deaf007837ba
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: jcomponent20@3fedd009a277f50fddc608b97afbec553b67c51b
Review: not-recorded

`AJAX('METHOD /url/', [data], callback)` envia um pedido e chama o callback com a resposta. As respostas JSON são interpretadas por si. Combine-o com `SET()` e qualquer `ui-bind` ou componente ligado ao caminho atualiza-se sozinho.

```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>
```
