Exemplo de Chamada a serviço REST/JSON

27 junho, 2009 (10:20) | dúvida | Por: admin

O exemplo abaixo é em JavaScript puro.
Dica: para chamar o serviço usando o jQuery, você pode usar as funções:
getJSON ou getScript.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>

    <script type="text/javascript">
        function exibirAleatorios(result) {
            //alert(result);
            //console.log(result);
            //alert(result.numbers[0]);
            for(i=0;i<result.numbers.length;i++) {
                alert(result.numbers[i]);
            }
        }
    </script>

    <script type="text/javascript"
    src="http://json-random.appjet.net/?num=5&min=10&max=20&callback=exibirAleatorios"></script>
</head>
<body>

</body>
</html>

Escreva um comentário