Link to home
Start Free TrialLog in
Avatar of dfghjk
dfghjk

asked on

How to get a AJAX code to work

Hi out there!
I'm trying to code a AJAX application, which I'm new to, and can't get it to work ok.
This code return error incompatible types at row: http.open("GET", modurl, true);
But when I had the code in a separate file it was the row http.onreadystatechange = useHttpResponse(x);
that returned the same error.
So I am not sure of which code it is that generate the error.
file test.htm:
<html><head>
<meta http-equiv="Content-Language" content="sv">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title></title>
<script language="javascript" >

function getXMLHTTPRequest() {
    var req = false;
    try { req = new XMLHttpRequest(); /* e.g. Firefox */ }
    catch(e) {
      try { req = new ActiveXObject("Msxml2.XMLHTTP"); /* Andra versioner av IE */ }
      catch(e) {
          try { req = new ActiveXObject("Microsoft.XMLHTTP"); /* Andra versioner av IE */ }
          catch (e) { req = false; }
        }}
    return req; }

  var http  = getXMLHTTPRequest();

  function getServerText(updateURL, updateId, updateName, updateValue, updateField, waitMessage)  {
    var x = document.getElementById(updateId)
    var myurl = updateURL+'?id='+updateId+'&value='+updateValue+'&field='+updateField
    myRand = parseInt(Math.random()*999999999999999);
    var modurl = myurl+"&rand="+myRand;
    http.open("GET", modurl, true);
    http.onreadystatechange = useHttpResponse(x);
    http.send(null);
  }

  function useHttpResponse(updateiId)
  {
    var y = document.getElementById(updateiId.id)
    if (http.readystate == 4) {
      if (http.status == 200)  {
        var mytext = http.responseText;
        y.value = mytext;
    }
      }  else {
       y.value = "WAIT...";
         }
  }
</script>

</head><body>
<form name="r">
<input id="P13" name="P_13" value="" onchange="getServerText('PP_RealTimeUpdate_Database.asp',this.id,this.name,this.value,'price','Uppdaterar...')">
</form>
</body></html>

I'd realy appreciate a tip of how to modify the code to get it to work.
The input filed(s) in the full scale application are very many (can be more than 1000) with id's from records in a database, and that id shall be returned to the server when cursor is living the input field, to update the databse with the fields value in realtime, without clicking any buttons. That is why I try to get this basic code to work for one field in this way!

The file 'PP_RealTimeUpdate_Database.asp' does only execute the line in this test:
<% Response.Write "ID:" & Request.QueryString("id") & "Val:" & Request.QueryString("value") & " Field:" & Request.QueryString("field") %>
to a string which will be returned when the application works ok.

Thanks in advance!
Zeth
ASKER CERTIFIED SOLUTION
Avatar of babuno5
babuno5
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dfghjk
dfghjk

ASKER

Thanks very much babuno5!
As very often in this world, the genious and good solutions is so simple and obvious, that one ask itself why one could not find it by itself!
Thanks again! Now I have something good working to build on!
Zeth