Post by kokenge on Jan 19, 2008 10:24:57 GMT -5
I have a small test program with some areas ID'd in a table.
This Client side program has some javascript that is called when I click the [Disp] button. All it does is tells the javascript program to call a program 'a_graph_be.bas' on the Server side. The Server Side should then display some data in the <TD ID=areas>
However when I show an alert box in the javascript of the response received from the Server I get about a page of html code.
What am I doing wrong....
Thanks for the help.
======================================
Here is the code
Stefan ... added code tags
This Client side program has some javascript that is called when I click the [Disp] button. All it does is tells the javascript program to call a program 'a_graph_be.bas' on the Server side. The Server Side should then display some data in the <TD ID=areas>
However when I show an alert box in the javascript of the response received from the Server I get about a page of html code.
What am I doing wrong....
Thanks for the help.
======================================
Here is the code
html "
<script language=""javascript"">
<!--
function createRequestObject()
{
var ro;
var browser = navigator.appName;
if(browser == ""Microsoft Internet Explorer"")
{
ro = new ActiveXObject(""Microsoft.XMLHTTP"");
}
else
{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function trim(string)
{
while (string.substring(0,1) == ' ')
{
string = string.substring(1, string.length);
}
while (string.substring(string.length-1, string.length) == ' ')
{
string = string.substring(0,string.length-1);
}
return string;
}
function handleResponse()
{
if(http.readyState == 4)
{
var response = http.responseText;
alert ('got back from server response:' + response);
var at = 0;
// --- strip leading junk ----
x = response.substring(0,1);
while (x < '0')
{
response = response.substring(1);
x = response.substring(0,1);
}
var update = new Array();
if(response.indexOf('|' != -1))
{
update = response.split('|');
x = update.length;
// alert ('update length:' + x);
for (i=0;i<x;i++)
{
update[i] = update[i].replace(/;;/g ,'|');
}
for (i=1;i<x;i=i+2)
{
at = i - 1;
update[at] = trim(update[at]);
// alert ('at:' + at + '|update[at]:' + update[at] + '|i:' + i + '|update[i]:' + update[i]);
try
{
ss = document.getElementById(update[at]);
ssv = ss.value;
sse = ss.element;
sst = ss.title;
ssn = ss.name;
ssi = ss.id;
ssh = ss.innerHTML;
// alert ('ss:' + ss + '|ssv:' + ssv + '|sse:' + sse + '|ssn:' + ssn + '|ssi:' + ssi + '|ssh:' + ssh + '|at:' + update[at] + '|i:' + update[i] );
if (ssv != undefined) ss.value = update[i];
else
if (ssh != undefined) ss.innerHTML = update[i];
}
catch(err)
{
alert ('Invalid display field:' + update[at]);
}
}
}
}
}
function trim(stringToTrim)
{
return stringToTrim.replace(/^\s+|\s+$/g,"""");
}
function ltrim(stringToTrim)
{
return stringToTrim.replace(/^\s+/,"""");
}
function rtrim(stringToTrim)
{
return stringToTrim.replace(/\s+$/,"""");
}
function server(prog)
{
prog = ltrim(prog); // Left trim
rs = http.readyState; // see if the previous task it done - state must be 0
if (rs == 4) rs = 0;
if (rs != 0)
{
rs = 0; // ?????? why don't this work ??????/
try
{
rs = http.readyState; // see if the previous task it done - state must be 0
}
catch(err)
{
rs = 1;
alert ('Server Busy. Please try again. Thank you and have a nice day ' + rs);
}
}
if (rs == 0)
{
prog1 = '';
xx = '';
if(prog.indexOf('|' != -1))
{
val = prog.split('|');
for ( key in val)
{
// alert('key:' + key + ' |val:' + val[key]);
x = '';
xx = val[key];
if (key & 1)
{
try
{
x = document.getElementById(xx).value;
toe = document.getElementById(xx).type; // type of element
chk = document.getElementById(xx).checked;
prog1 = prog1 + x;
}
catch(err)
{
// alert ('--error----xx:' + xx + '|err:' + err.description);
prog1 = prog1 + err.description;
}
// alert ('------x:' + x + '| toe:' + toe + '| chk:' + chk);
}
else prog1 = prog1 + xx;
}
}
//alert ('server side get program| prog1:' + prog1);
http.open('get', prog1);
http.onreadystatechange = handleResponse;
http.send(null);
}
}
//--></script>
"
html "<B>Test Ajax Call"
html "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 BGCOLOR='#A0A0A4'>
<TR>
<TD VALIGN='BOTTOM' id=g1><img src='http://localhost:8008/tub_cya.gif' width=18 HEIGHT=55 BORDER=0></TD>
<TD VALIGN='BOTTOM' id=g2><img src='http://localhost:8008/tub_ppl.gif' width=18 HEIGHT=45 BORDER=0></TD>
<TD id=g3>A</TD></TR>
<TR><TD><div id=g4>B</div></TD>
<TD>C</TD>
<TD>D</TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
<TD><INPUT TYPE='BUTTON' Value='Disp' onCLick=""server('a_graph_be.bas?entry=new_line&add_line=1');"">
</TD>
</TR>
</TABLE>
"
Stefan ... added code tags