js簡単なgetの小さい例

1266 ワード

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>  
  
    <script type="text/javascript">
     $(function () {
         $.ajax({
           url: 'http://localhost:8000/api/posts/',
             type: 'GET',
             dataType: 'jsonp',
             timeout: 1000,
             cache: false,
             beforeSend: LoadFunction,   
             error: erryFunction,    
             success: succFunction   
         })
         function LoadFunction() {
             $("#list").html('   ...');
         }
         function erryFunction() {
             alert("error");
         }
         function succFunction(data) {
             //alert("    ");
             //$("#list").html('');
           
           $(data).each(function(i){
                        for(key in this)
                            alert(data[i][key]);
                        });
         }
       });
</script>

</head>
<body>
<ul id="list">
    </ul>
</body>
</html>