Advertisement
afterlife88

Untitled

Sep 21st, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.     var baseUri = "/api/Configuration";
  3.  
  4.     function loadList() {
  5.         $.ajax({
  6.             url: baseUri,
  7.  
  8.             success: function(config) {
  9.  
  10.                 var list = $("#names");
  11.                 list.empty();
  12.  
  13.                 for (var i = 0; i < config.length; i++) {
  14.                     var name = config[i].ConfigName;
  15.                     var email = config[i].EmailAdress;
  16.                     var hostname = config[i].HostingName;
  17.                     var ftpusername = config[i].FtpUserName;
  18.                     var registration = config[i].Registration;
  19.                     var typeofhost = config[i].TypeOfHosting;
  20.                     list.append("<dl>" + "<b>" + 'Configuration Name: ' + "</b>" + name + "</dl>");
  21.                     list.append("<dt>" + 'EmailAdress: ' + email + "</dt>");
  22.                     list.append("<dt>" + 'HostingName: ' + hostname + "</dt>");
  23.                     list.append("<dt>" + 'FtpUserName: ' + ftpusername + "</dt>");
  24.                     list.append("<dt>" + 'Registration: ' + registration + "</dt>");
  25.                     list.append("<dt>" + 'TypeOfHosting: ' + typeofhost + "</dt>");
  26.                 }
  27.             }
  28.         });
  29.     }
  30.  
  31.     loadList();
  32.     $(document).ready(function() {
  33.         $("#addNewBtn").on("click", postConfig);
  34.     });
  35.  
  36.     function postConfig() {
  37.         var config = {};
  38.         config.configName = $("#configName").val();
  39.         config.email = $("#emailAdress").val();
  40.         config.host = $("#hostingName").val();
  41.         config.ftpUser = $("#HostingName").val();
  42.         config.configName = $("#ftpUserName").val();
  43.         config.typerOfHost = $("#typeOfHosting").val();
  44.  
  45.  
  46.         $.ajax({
  47.             url: baseUri,
  48.             type: "POST",
  49.             data: JSON.stringify(email),
  50.             dataType: "json",
  51.             contentType: "application/json",
  52.             success:  loadList(),
  53.            
  54.             error: errorHandler,
  55.             statusCode: {
  56.                 201: function() {
  57.                     alert("Created. Имя успешно добавлено в коллекцию.");
  58.                 },
  59.                 400: function() {
  60.                     alert("Bad Request. Операция не выполнена.");
  61.                 }
  62.             }
  63.            
  64.         });
  65.     }
  66.     function errorHandler(xhr, textStatus, error) {
  67.         if (xhr.status == "404") {
  68.             alert('Элемент не найден.')
  69.         }
  70.         else if (xhr.status == "400") {
  71.             alert('Запрос сформирован не правильно.')
  72.         }
  73.         else if (xhr.status == "500") {
  74.             alert('Ошибка сервера.')
  75.         }
  76.     }
  77. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement