JSFiddle - React, Tailwind, and code Playground

by enlightenmedia

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<div ng-app="myApp">
    <div ng-controller="myCtrl">
        <button ng-click="callajax()">Call Ajax</button>
    </div>

</div>

JavaScript

var myApp = angular.module('myApp', []);

myApp.controller('myCtrl',function($scope, $http, $q) {
    var canceller,
        isSending = false;
    $scope.callajax = function () {
        console.log("callajax");
        if(isSending) {
            canceller.resolve()
        }
        isSending = true;
        canceller = $q.defer();
        
        var data = {
                html: "<p>Text echoed back to request</p>",
                delay: 5
            }
        $http({
            method: "post",
            url: "/echo/html",
            data: data,
            timeout: canceller.promise
        }).success(function (response) {
            isSending = false;
            console.log("success");
        }).error(function(data, status) {            
            isSending = false;
            console.log("error");
      });;
    }; 
});