dns-daniel
9/21/2016 - 4:28 AM

AJAX Example via jQuery

AJAX Example via jQuery

    <script type="text/javascript">
      $("document").ready(function() {
        getData();
      });
      
      function getData() {
        $.ajax({
          // the URL for the request
          url: "testdata.txt",

          // whether this is a POST or GET request
          type: "GET",
         
          // the type of data we expect back
          dataType : "text"
        })
        .done(successFn)
        .fail(errorFn)
        .always(function (data, textStatus, jqXHR ) {
            console.log("The request is complete!");
        });
      }
      
      function successFn(data, status, jqXHR) {
        console.log("Setting result");
      	$("#content").append(data);
      }
      function errorFn(xhr, status, strErr) {
        console.log("There was an error!");
      }
  </script>