Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!doctype html>
<html ng-app>
  <head>
    <script src="http://code.angularjs.org/angular-1.0.1.min.js"></script>
    <script>
    function FetchCtrl($scope, $http, $templateCache) {
          $scope.method = 'GET';
          $scope.url = 'http-hello.html';
         
          $scope.fetch = function() {
            $scope.code = null;
            $scope.response = null;
         
            $http({method: $scope.method, url: $scope.url, cache: $templateCache}).
              success(function(data, status) {
                $scope.status = status;
                $scope.data = data;
              }).
              error(function(data, status) {
                $scope.data = data || "Request failed";
                $scope.status = status;
            });
          };
         
          $scope.updateModel = function(method, url) {
            $scope.method = method;
            $scope.url = url;
          };
        }
      function getdata(data){
        console.log(data)
      }
    </script>
  </head>
  <body>
    <div ng-controller="FetchCtrl">
      <select ng-model="method">
        <option>GET</option>
        <option>JSONP</option>
      </select>
      <input type="text" ng-model="url" size="80"/>
      <button ng-click="fetch()">fetch</button><br>
      <button ng-click="updateModel('GET', 'http-hello.html')">Sample GET</button>
      <button ng-click="updateModel('JSONP', 'http://angularjs.org/greet.php?callback=getdata&name=Super%20Hero')">Sample JSONP</button>
      <button ng-click="updateModel('JSONP', 'http://angularjs.org/doesntexist&callback=JSON_CALLBACK')">Invalid JSONP</button>
      <pre>http status code: {{status}}</pre>
      <pre>http response data: {{data}}</pre>
    </div>
    
    <script type="text/ng-template" id="http-hello.html">Hello, $http!</script>
  </body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers