Thursday, February 23, 2012

My browser talks to the machine!!

I managed the http thing, it is not my first time but each time I try to forget. Anyway, I can at least point my browser at the engine and it responds hello. So in Javascript, I can at least et at it through the anchor (link) syntax). I can't get javascript send to work the way I want, but this is OK for now.

I have it working through an html form, using get and now post. So I created the LazyJ http protocol, make a form, submit to local host as a post with the name LazyJ. The engine will find the LazY text and run it through.

The trick:
function http_io()
    {

    obj = new XMLHttpRequest();
 obj.onreadystatechange = function() {
 alert('on change ' + obj.status + obj.getAllResponseHeaders());
  if (obj.readyState==4) {
  if (obj.status!=404) {
    alert(obj.responseText);
   } else {
    alert("Whoops");
   }
 }
   }
 alert('new ' + obj.readyState);
  obj.open("POST", "http://localhost:8000", true);
  alert('open ' + obj.readyState);
  obj.setRequestHeader( "Content-Type", "multipart/form-data");
 obj.send( document.getElementById("input").value); //text/plain;charset=UTF-8;charset=UTF-8
 //obj.send();
 alert("sent " + obj.readyState);
    }

I triggger this clikc with:

 <textarea id = "input" rows="2" cols="20">
Some input
</textarea>
  <a href="" onClick=http_io()>Link</a>

In my test.html file.  I put test.html and the g engine code in the same directory.  The transfer is plain, undoctored bytes from the text area, exactly what I want.  And the header code is still just a few lines of key word search then go on to the content.  The system is compatible with the console, so the same code still works.  I will upload my little test.html. This will speed things up enormously.

But what is the draw back here?
The machine does not know client server,. It knows that it received a self directed Json graph, and it runs it through the machine.  If the Json was trying for client server, then Json is lost.  That's ok for the lab and alpha, launch and forget.  So I worry that later.

No comments: