Yun not connecting to router through LAN and my web page seems glitchy

Hi everyone,

I'm rather new to forums in general but I'm trying to setup a web page based yun control so I can eventually control SSRs to turn on and off electronics around my apartment. I based my codes off of someone's "tutorial" on this site. http://www.open-electronics.org/interact-and-remotely-control-arduino-yun-with-ajax/ The page that is generated looks great, but it has a wicked long delay between communications and half the time it either doesn't change the picture I use to show whether the light output is high or low. I'm super basic when it comes to javascript and can't decipher what I'm reading. I am however a little more versed in C/C++ and am capable of figuring out what may be wrong with the Arduino code.

This is the Arduino code that I have. My java/HTML/XML (not to sure which it is) code is posted after. Can someone help me figure out as to why my yun won't connect / have super long delays / not change the picture?

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
int dac[] = {0, 0, 0, 0, 0, 0, 0};
int DigitalPin[] = {2, 4, 7, 8, 9, 10, 11, 12, 13};
int DacPin[] = {3, 5, 6};
YunServer server;
void setup() 
{
  pinMode(3,INPUT);
  pinMode(4,INPUT);
  pinMode(7,INPUT);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(13,OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  digitalWrite(13, HIGH);
  server.listenOnLocalhost();
  server.begin();
}

void loop() 
{
  YunClient client = server.accept();
  if (client) {
  process(client);
  client.stop();
  }
  delay(50);
}

void process(YunClient client) 
{
  String command = client.readStringUntil('/');
  if (command == "digital") {
  digitalCommand(client);
  }
  if (command == "analog") {
  analogCommand(client);
  }
  if (command == "dac") {
  dacCommand(client);
  }
  if (command == "state") {
  stateCommand(client);
  }
}

void digitalCommand(YunClient client) 
{
  int pin, value;
  
  pin = client.parseInt();
  
  if (client.read() == '/') 
  {
    value = client.parseInt();
    digitalWrite(pin, value);
  }
  else 
  {
    value = digitalRead(pin);
  }
  
  client.print(F("analog,"));
  client.print(pin);
  client.print(F(","));
  client.println(value);
}

void dacCommand(YunClient client) 
{
  int pin, value;
  pin = client.parseInt();
  
  if (client.read() == '/') 
  {
    value = client.parseInt();
    dac[pin] = value;
    analogWrite(pin, value);
  }
  else {
    value = dac[pin];
  }
  client.print(F("dac,"));
  client.print(pin);
  client.print(F(","));
  client.println(value);
}


void stateCommand(YunClient client) 
{
  int pin, value;
  client.print(F("state"));
  for (int thisPin = 0; thisPin < 9; thisPin++) 
  {
    pin = DigitalPin[thisPin];
    value = digitalRead(pin);
    client.print(F("#"));
    client.print(pin);
    client.print(F("="));
    client.print(value);
  }
  for (int thisPin = 0; thisPin < 3; thisPin++)
  {
    pin = DacPin[thisPin];
    value = dac[pin];
    client.print(F("#"));
    client.print(pin);
    client.print(F("="));
    client.print(value);
  }
  for (int thisPin = 0; thisPin < 6; thisPin++) 
  {
    value = analogRead(thisPin);
    value = analogRead(thisPin);
    client.print(F("#A"));
    client.print(thisPin);
    client.print(F("="));
    client.print(value);
  }
  client.println("");
}
<html>
	<head>
	<title>Arduino Yun I/O shield</title>
		<script type="text/javascript">
			window.onload=ChargeStatePin;
			function ChargeStatePin()
			{
				readState();
			}
			
		function readState()
		{
			setTimeout(readState, 2000);
			document.getElementById("description").innerHTML = "--- Wait ... ---";
			server = "/arduino/State/99";
			request = new XMLHttpRequest();
			request.onreadystatechange = updateasynchronousState;
			request.open("GET", server, true);
			request.send(null);
		}

		function updateasynchronousState()
		{
			if ((request.readyState == 4) && (request.status == 200))
			{
				outcome = request.responseText;
				document.getElementById("description").innerHTML = outcome;
				pippo = outcome.split("#");
				document.getElementById("description").innerHTML = pippo;
				for(i = 1; i < pippo.length; i++)
				{
					PinPair = pippo[i];	
					iparr = PinPair.split("=");
					PN = iparr[0];
					PinState = iparr[1];
					if (PN > 7)
					{
						ActNum = "action" + PN;
						ImgNum = "image" + PN;
						if (PinState == 0)
						{
							PinAct = "1";
							Image = "off.jpg";
						}
						else
						{
							PinAct = "0";
							Image = "on.jpg";
						}
						document.getElementById(ActNum).value = PinAct;
						document.getElementById(ImgNum).src = Image;
					}
					if (PN == 2 || PN == 4 || PN == 7)
					{
						ImgNum = "image" + PN;
						if (PinState == 1)
						{
							Image = "led_off.jpg";
						}
						else
						{
							Image = "led_on.jpg";
						}
						document.getElementById(ImgNum).src = Image;
					}
					if (PN == 3 || PN == 5 || PN == 6)
					{
						PinVal = parseInt(iparr[1]);
						DacNum = "dac" + PN;
						ValNum = "ValueDac" + PN;
						document.getElementById(DacNum).value = PinVal;
						document.getElementById(ValNum).innerHTML = PinVal;
					}	
				}
			}
		}

		function sendRelay(Pin,Action)
		{
			document.getElementById("description").innerHTML = "--- Wait ... ---";
			server = "/arduino/digital/" + Pin + "/" + Action;
			request = new XMLHttpRequest();
			request.onreadystatechange = updateasynchronousRelay;
			request.open("GET", server, true);
			request.send(null);
		}
		function updateasynchronousRelay()
		{
			if ((request.readyState == 4) && (request.status == 200))
			{
				outcome = request.responseText;
				document.getElementById("description").innerHTML = outcome;
				iparr = outcome.split(",");
				PinType = iparr[0];
				PinNum = iparr[1];
				PinState = iparr[2];
				ActNum = "action" + PinNum;
				ImgNum = "image" + PinNum;
				
				if (PinState == 0)
				{
					PinAct = "1";
					Image = "off.jpg";
				}
				else
				{
					PinAct = "0";
					Image = "on.jpg";
				}
				
				document.getElementById(ActNum).value = PinAct;
				document.getElementById(ImgNum).src = Image;
				document.getElementById("description").innerHTML = outcome;
			}
		}
		function sendDac(Pin,Value)
		{
			ValNum = "ValueDac" + Pin;
			document.getElementById(ValNum).innerHTML=Value;
			document.getElementById("description").innerHTML = "--- Wait ... ---";
			server = "/arduino/dac/" + Pin + "/" + Value;
			request = new XMLHttpRequest();
			request.onreadystatechange = updateasynchronousDac;
			request.open("GET", server, true);
			request.send(null);
		}
		function updateasynchronousDac()
		{
			if ((request.readyState == 4) && (request.status == 200))
			{
				outcome = request.responseText;
				iparr = outcome.split(",");
				PinType = iparr[0];
				PinNum = iparr[1];
				PinVal = parseInt(iparr[2]);
				DacNum = "dac" + PinNum;
				ValNum = "ValueDac" + PinNum;
				document.getElementById(DacNum).value = PinVal;
				document.getElementById(ValNum).innerHTML = PinVal;
				document.getElementById("description").innerHTML = outcome;
			}
		}
		
		function updateasynchronousDigital()
		{
			if ((request.readyState == 4) && (request.status == 200))
			{
				outcome = request.responseText;
				document.getElementById("description").innerHTML = outcome;
				iparr = outcome.split(",");
				PinType = iparr[0];
				PinNum = iparr[1];
				PinState = iparr[2];
				ImgNum = "image" + PinNum;
				
				if (PinState == 1)
				{
					Image = "led_off.jpg";
				}
				else
				{
					Image = "led_on.jpg";
				}
				
				document.getElementById(ImgNum).src = Image;
				document.getElementById("description").innerHTML = outcome;
			}
		}
		</script>
	</head>
	
	<font face="Arial">
		<table name="Titolo" border="1" style="width: 456px;" cellpadding="6">
			<tr> <th align="center" colspan="6" >Arduino Yún I/O shield</th></tr>
		</table>
		<table name="Tabella" border="1" cellpadding="6">
			<tr> <th align="center" colspan="6" >Relay Outputs</th></tr>
			<tr>
				<td align="center">
					13
					

					<input type="hidden" name="pin" value="13" id="pin13" />
					<input type="hidden" name="action" value="0" id="action13" />
					<img src="off.jpg" width="50" id="image13"
					onclick="sendRelay(document.getElementById('pin13').value,
					document.getElementById('action13').value);"
					/>
				</td>
				<td align="center">
					12
					

					<input type="hidden" name="pin" value="12" id="pin12" />
					<input type="hidden" name="action" value="0" id="action12" />
					<img src="off.jpg" width="50" id="image12"
					onclick="sendRelay(document.getElementById('pin12').value,
					document.getElementById('action12').value);"
					/>
				</td>
				<td align="center">
					11
					

					<input type="hidden" name="pin" value="11" id="pin11" />
					<input type="hidden" name="action" value="0" id="action11" />
					<img src="off.jpg" width="50" id="image11"
					onclick="sendRelay(document.getElementById('pin11').value,
					document.getElementById('action11').value);"
					/>
				</td>
				<td align="center">
					10
					

					<input type="hidden" name="pin" value="10" id="pin10" />
					<input type="hidden" name="action" value="0" id="action10" />
					<img src="off.jpg" width="50" id="image10"
					onclick="sendRelay(document.getElementById('pin10').value,
					document.getElementById('action10').value);"
					/>
				</td>
				<td align="center">
					9
					

					<input type="hidden" name="pin" value="9" id="pin9" />
					<input type="hidden" name="action" value="0" id="action9" />
					<img src="off.jpg" width="50" id="image9"
					onclick="sendRelay(document.getElementById('pin9').value,
					document.getElementById('action9').value);"
					/>
				</td>
				<td align="center">
					8
					

					<input type="hidden" name="pin" value="8" id="pin8" />
					<input type="hidden" name="action" value="0" id="action8" />
					<img src="off.jpg" width="50" id="image8"
					onclick="sendRelay(document.getElementById('pin8').value,
					document.getElementById('action8').value);"
					/>
				</td>
			</tr>
			
			<tr> <th align="center" colspan="6" >Digital Inputs (2 4 7) and DAC (3 5 6)</th></tr>
			<tr>
				<td align="center">
					2
					

					<img src="led_off.jpg" width="50" id="image2" />
				</td>
				<td align="center">
					3
					

					<input type="hidden" name="pin" value="3" id="pin3" />
					<input type="range" style="width: 50px; height: 30px;" id="dac3" min="0" max="255" value="0" step="1"
					onchange="sendDac(document.getElementById('pin3').value,
					this.value);"
					/>
					

					<span id="ValueDac3">0</span>
				</td>
				<td align="center">
					4
					

					<img src="led_off.jpg" width="50" id="image4" />
				</td>
				<td align="center">
					5
					

					<input type="hidden" name="pin" value="5" id="pin5" />
					<input type="range" style="width: 50px; height: 30px;" id="dac5" min="0" max="255" value="0" step="1"
					onchange="sendDac(document.getElementById('pin5').value,
					this.value);"
					/>
					

					<span id="ValueDac5">0</span>
				</td>
				<td align="center">
					6
					

					<input type="hidden" name="pin" value="6" id="pin6" />
					<input type="range" style="width: 50px; height: 30px;" id="dac6" min="0" max="255" value="0" step="1"
					onchange="sendDac(document.getElementById('pin6').value,
					this.value);"
					/>
					

					<span id="ValueDac6">0</span>
				</td>
				<td align="center">
					7
					

					<img src="led_off.jpg" width="50" id="image7" />
				</td>
			</tr>
		</table>
		


		


		<p id="description"> - </p>
	</font>
</html>