Shop OBEX P1 Docs P2 Docs Learn Events
PINK - javascript problem using src= in <script> tag — Parallax Forums

PINK - javascript problem using src= in <script> tag

Ron CzapalaRon Czapala Posts: 2,418
edited 2009-10-18 01:36 in BASIC Stamp
I found a peculiar problem when·including·a javascript file with the src parameter of the <script> tag.·The·html and javascript files are shown below.

If the·dash is removed in the func_one alert statement (e.g.··'No http request capability'), the entire function is not served by the PINK module when using IE8 (works under FireFox). It's like the "http" in the literal string causes a problem. Changing it to "httpx" works and changing the file extension to .txt instead of .js works.

I might be a mime type problem with the PINK module not mapping the .js suffix to the application/x-javascript in the HHTP header or maybe it's an issue with IE8.

You can see what is returned by browsing to http://192.168.1.104/prob.js· (use your particular ip address of course). func_one does not even appear unless you modify the http literal.

It took a while to figure out what was happening but curious nonetheless!
<html>
<head>
<title></title>
<script type="text/javascript" language="javascript" src="prob.js"></script>
</head>
<body>
  Demo javascript problem 
  <input type="button" value="One" onclick="return func_one()" id=button1 name=button1>
  <br>
  <input type="button" value="two" onclick="return func_two('Test func two')" id=button2 name=button2>
  <br>
  <input type="button" value="three" onclick="return func_three('doc write test')" id=button3 name=button3>
</body>
</html>

function func_one() {
 alert('No http-request capability');
}
function func_two(sendtext){
  alert(sendtext);
}
function func_three(sendtext) {
  document.write(sendtext);
}

Comments

  • AJ ScottAJ Scott Posts: 9
    edited 2009-10-17 21:22
    The applicability with a Parallax Stamp module is??
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2009-10-17 21:50
    AJ Scott - The applicability with a Parallax Stamp module is??

    · The actual html and javascript in which I discovered the problem was more complex and uses xmlhttprequest to update PINK variables and send emails using basic stamp code.

    To illustrate the problem I created this little demo html and javscript file to avoid any confusion·with the original BS2/Pink application.

    function getXMLHttpRequest() {
      if (window.XMLHttpRequest) {
        return new window.XMLHttpRequest;
      }else{
        try {
          return new ActiveXObject('MSXML2.XMLHTTP.3.0');
        }
        catch(err) {
          alert('No http-request capability');
          return null;
        }
      }
    }
    

    function processReqChange() {
      if (xmlRequest.readyState == 4) {
        if (xmlRequest.status == 200) {
    //    alert(xmlRequest.responseText);   //    ...processing statements go here...
    //    respval.innerText = xmlRequest.responseText; 
        }else{
          alert("There was a problem sending the XML data:\n" +
                xmlRequest.status + " " + xmlRequest.statusText);
        }        
      }
    }
    function HttpReqPost(URL, sendtext) {
    //  var URL;
    //  URL = "DEFAULTSET.HTM "; 
      
      xmlRequest = getXMLHttpRequest();
      xmlRequest.open("post", URL);
      //xmlRequest.setRequestHeader("variable", "");
      xmlRequest.setRequestHeader("Content-Type", "text/xml");
      //xmlRequest.setRequestHeader("Connection", "close");
      xmlRequest.onreadystatechange = processReqChange;
      xmlRequest.send(sendtext);
    }
    

    ·
  • AJ ScottAJ Scott Posts: 9
    edited 2009-10-17 23:15
    Root is almost never allowed script source permissions. Script sources should be in a virtual directory within the root tree. Your issue is likely a configuration issue with IIS.
  • AJ ScottAJ Scott Posts: 9
    edited 2009-10-17 23:25
    Please show your server code that is making calls to the server object capable of serial communication with the BS2.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-10-17 23:33
    I noticed you mentioned that this happens with IE8. Have you tried any other browsers?

    Also, if you're using the PINK module then IIS doesn't have anything to do with this issue.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2009-10-18 00:00
    Chris,
    ·· The html/javascript works with FireFox and works locally on IIS using IE8 so I think it must be the way the PINK Netburner handles the .js file.

    As I mentioned, if I rename the javascript file to prob.txt and change the script include to:
    <script type="text/javascript" language="javascript" src="prob.txt"></script>
    it works fine. This leads to to believe that the PINK is not using the right mime type (but somehow FireFox handles it?!?)
    Maybe the netburner·was not designed/programmed to handle .js files.

    If the javascript functions are moved into the html file, it also works.

    Could not find any info on the netburner web site http://www.netburner.com/products/serial_to_ethernet/sb70.html






    Post Edited (ronczap) : 10/18/2009 12:17:03 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-10-18 00:05
    Unlike some components Javascript is a client side language...the server is merely the host. This is why I am a little confused as to what's happening.· If there is a failure it should be in the browser and have nothing to do with the server.· The only thing I can think of is a communication issue.· Just out of curiosity what happens if you use IE8's compatibility mode?· Also, you're not useing the 64-bit IE8 are you?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2009-10-18 00:12
    Chris,

    Javacript is client side of course, but so is html but the PINK module manipulates the html before sending it (to make variable substitutions) and it may also be processing the .js file before it is sent. This might·explain why it works with a .txt extension but not with .js

    Compatibility mode has no effect. I am running XP professional (32 bit).

    It is not a big deal but I wanted people who use the PINK to be aware.

    It is a strange problem. Browsing to the .js file shows only the second and 3rd functions (if the first one has " http" in the literal.


    Post Edited (ronczap) : 10/18/2009 12:21:34 AM GMT
  • AJ ScottAJ Scott Posts: 9
    edited 2009-10-18 00:17
    Its in my opinion a ser4ver permissions issue. .js is flagged as a script whereas .txt is of mime type text/plain and is not scrutinized by IIS. It runs locally on the server side because you as a user have rights locally and the browser automatically logs you into IIS with rights. Remotely you are authenticated as IUser, a very restricted credential. Move your script source to virtual directory /scripts and adjust your src= to read "/scripts/prob.js" then try it remotely.
  • AJ ScottAJ Scott Posts: 9
    edited 2009-10-18 00:21
    Your local path for the scripts directory on the server is "c:\inetpub\scripts" scripts is not a child of wwwroot, but is a folder mapping to http://servername/scripts.
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2009-10-18 00:22
    AJ -

    ··· The PINK module is the server - this has nothing to do with permissions under the operating system. The PINK module is connected directly to the router.

    I was a web application developer before I retired and I understand the IIS configuration.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-10-18 01:36
    Well I appreciate your findings...nobody has ever reported this issue before when using the PINK module.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
Sign In or Register to comment.