Note that there are some explanatory texts on larger screens.

plurals
  1. POexternal java script file not working
    primarykey
    data
    text
    <p>I'm doing a project for school and so far it's been a lot of copy this script and paste it here to make things "work". I don't really have any idea what I'm doing besides comparing one line of code to another and looking for the differences.</p> <p>I've got javascript that is returning some values to me and it works fine when it's in a simple webpage format but when I insert it into a more complicated page it stops working.</p> <p>At the very end of the page it should give a line of numeric values and be updated every 1000 milliseconds but what happens is it just sits there displaying Temp()...</p> <p>I've checked the data.xml and those values are being updated when I push buttons and stuff on my PIC protoboard.</p> <p>I'm using the same ajax.js file for both the simple webpage and the complicated page. I'm thinking it is something simple like a missed <code>&lt;/p&gt;</code> or <code>&lt;/div&gt;</code> tag but my eyes don't seem to see it.</p> <p>Could some take a look at the code and see what I've missed? Thanks!</p> <p><strong>ajax.js</strong></p> <pre><code> var xhr; function getXMLHttpRequest(){ try { return new ActiveXObject("Msxm12.XMLHTTP"); } catch(e){}; try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){}; try { return new XMLHttpRequest(); } catch(e){}; return null; } function parseHttpResponse(){ if(xhr.readyState == 4){ if(xhr.status == 200){ document.getElementById("T0").innerHTML=xhr.responseText; } else { } } } function getTemp(){ xhr = getXMLHttpRequest(); xhr.open("GET", "data.xml", true); xhr.onreadystatechange = parseHttpResponse; xhr.send(null); } setInterval("getTemp()", 1000); </code></pre> <p><strong>Simple webpage - this works great</strong></p> <pre><code> &lt;html&gt; &lt;head&gt;&lt;title&gt;Ajax test - index1&lt;/title&gt; &lt;script src="ajax.js" type="text/javascript"&gt; &lt;/script&gt; &lt;/head&gt; &lt;body onload="getTemp();"&gt; &lt;h2&gt;Headline&lt;/h2&gt; &lt;p&gt;Paragraph&lt;/p&gt; &lt;div id='T0'&gt;Loading Temp0...&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>"Complicated" webpage - when this is used I get no joy</strong></p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Elex267-Webpage&lt;/title&gt; &lt;script src="ajax.js" type="test/javascript"&gt; &lt;/script&gt; &lt;link rel="stylesheet" href="myStyle.css" type="text/css" &gt; &lt;/head&gt; &lt;body onload="getTemp();"&gt; &lt;!-- Banner at Top of Page ***********************************--&gt; &lt;div style="background-color:blue; color:white;font-size:30px;"&gt; &lt;img src="Pics/camosun-white.png" alt="CamosunPNG" width="200" height="70" align="left"&gt; &lt;div align="center"style="margin-left:50%"&gt;Elex 267 Web Demo &lt;br&gt; Microchip TCP/IP Stack v3.02&lt;/div&gt; &lt;/div&gt; &lt;!--*********************************************************--&gt; &lt;!--NavBar Code *********************************************--&gt; &lt;div class="nav"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="index.htm"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="features.htm"&gt;Features&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="about.htm"&gt;About&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;!--***************************************************--&gt; &lt;p&gt; Welcome to the Elex 267 Demo Web Server for [Name Here].&lt;br&gt; &lt;/p&gt; &lt;p&gt; This web page is being run on the NM101 NorthMicro Pic Prototype Board with the LCD/Keypad and Network modules. &lt;br&gt; This web page refreshes the data every 3 seconds. &lt;/p&gt; &lt;center&gt; &lt;img border="5" src="http://www.northmicro.com/GFX/nm110nm120onproto.jpg" alt="NM110 Proto Pic" width="200" height="200" &gt; &lt;/center&gt; &lt;br&gt; &lt;div id="feedback" style="width:500px;float:left;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Pot RA0: 1022 &lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Pot RA1: 223 &lt;br&gt;&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Switch RA2: &lt;img src="Pics/SwitchUp.gif" alt="SwitchOff" width="20" height="20" align="top"&gt; &lt;br&gt;&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LEDs:&amp;nbsp;&amp;nbsp;RB6 &lt;img src="Pics/LEDOff.gif" alt="LED_Off" width="20" height="20" align="top"&gt; &amp;nbsp;&amp;nbsp;RB5 &lt;img src="Pics/LEDOn.gif" alt="LED_On" width="20" height="20" align="top"&gt; &lt;/div&gt; &lt;div id="input" style="width=50%;margin-left:50%;"&gt; &lt;b&gt;Commands&lt;/b&gt;&lt;br&gt; &lt;button align="left" type="button" onclick="alert ('RB5 Activated')"&gt;Toggle RB5&lt;/button&gt; &lt;br&gt; &lt;button align="left" type="button" onclick="alert ('RB6 Activated')"&gt;Toggle RB6&lt;/button&gt; &lt;/div&gt; &lt;br&gt;&lt;br&gt; &lt;div id='T0'&gt;Loading Temp0...&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload