Define the domain to operate as a property in Delegate.js; placed JSONifying code in Delegate.js as well; closes #4

This commit is contained in:
Kaelin Hooper
2016-06-20 09:42:36 -07:00
parent 45891a5fd1
commit 9cb2eaa498
3 changed files with 7 additions and 50 deletions
@@ -1,44 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace PerfViewService.Controllers
{
[Route("api/[controller]")]
public class ValuesController : Controller
{
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "Item1", "Item2" };
}
// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public void Post([FromBody]string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
@@ -1,17 +1,19 @@
function Delegate() {
var self = this;
var self = this;
var domain = "http://localhost:5000";
this.log = function log(status) {
$("#statusBar span").text(status);
}
this.httpGet = function httpGet(url, callback) {
url = domain + url;
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
self.log("GET " + url + " Complete");
callback(xmlHttp.responseText);
self.log("GET " + url + " Complete");
callback(JSON.parse(xmlHttp.responseText));
} else {
self.log("GET " + url + " " + xmlHttp.status);
}
@@ -168,9 +168,8 @@
<script>
// GET all directories and items and append them to tree view
$(document).ready( function() {
treeView = delegate.httpGet("http://localhost:5000/api/data/open", function (response) {
var tree = JSON.parse(response);
items = tree.items;
treeView = delegate.httpGet("/api/data/open", function (response) {
items = response.items;
var htmlFromJSON = createTreeFromJSON(items);
$("#mainTree").append(htmlFromJSON);
delegate.log("Completed: View");