Problem with WebSpeed's return w/ AJAX & JS

Still a great product, but shouldn't you be using ps:eScript?

Moderator: matt

Problem with WebSpeed's return w/ AJAX & JS

Postby tbaxter99 » Wed Nov 21, 2007 9:07 pm

Hi All !... hope someone out there can help me... I'm using Progress V9...
straight character based, nothing fancy, and I've created a Javascript
which uses AJAX to make a asyncronous call to the server for a very
simple customer lookup, return name... the program which runs,
uses the {&OUT} webspeed stream to return a value to the calling
JavaScript section of the html... the values are returned just fine...
although I have to "strip-off" the webspeed header... immediately
after I grab the returned variables, something weird happens...
a new webpage is generated, and the returned value is displayed
on this page... I just want to grab the return values, and sail on
my merry way without displaying an additional webpage...
anyone out there have any ideas ?
thanks,
Terry
tbaxter99
Contributor
 
Posts: 2
Joined: Wed Nov 21, 2007 8:56 pm

Re: Problem with WebSpeed's return w/ AJAX & JS

Postby matt » Wed Nov 21, 2007 9:56 pm

Hi Terry,

Can you post some code, it'll be easier help you out.

Regards,

Matt.
matt
ps:eScript Creator
 
Posts: 55
Joined: Mon Jul 03, 2006 8:12 pm
Location: UK

Re: Problem with WebSpeed's return w/ AJAX & JS

Postby tbaxter99 » Thu Nov 22, 2007 4:38 am

A-OK... as per your request... there are 3 programs involved with this...
The programs work properly, and DO display a "looked-up" customer
name... but... we get the extra blasted white html screen which ALSO
shows the returned value BUT WITH the pipe-separator, ie. the entire
value returned by the lookup routine...

Program 1: Outputs an html page having an enterable customer number
field, and calls the JavaScript, getcustname(), which fires
up AJAX and invokes the lookup program through a security
checking "dispatch" routine.
/*******************************************************************************
/******************************************************************************/
/* JAVASCRIPT */
/******************************************************************************/
phtml =
'<script language - "javascript">'
' try'
' \{'
' Lookup = new XMLHttpRequest();'
' \}'
' catch(trymicrosoft)'
' \{'
' try'
' \{'
' Lookup = new ActiveXObject("Msxml2.XMLHTTP");' /* Later IE versions */
' \}' /* try */
' catch(othermicrosoft)'

' \{'
' try'
' \{'
' Lookup = new ActiveXObject("Microsoft.XMLHttp");' /* Early IE versions */
' \}' /* try */
' catch(failed)' /* Connection failed */

' \{'
' alert("AJAX Lookups are NOT FUNCTIONAL !")'
' \}'
' \}'

' \}'
.

phtml =
' function getcustname()'
'\{'
' var custno = document.getElementById("CustNo").value;'
' var url = location.href="' + HostURL + AppURL
+ vAjaxObject
+ 'ProgID=100100' /* 100100 = lku_cust.p */
+ '&SID=' + vSID
+ '&CustNo=" + custno'
'Lookup.open("GET", url, true);'
'Lookup.onreadystatechange = showcustname;'
'Lookup.send(null);'
'\}' /* function getcustname */
.

phtml =
' function showcustname()'
'\{'
' if (Lookup.readyState == 4)'
' \{'
' if (Lookup.status == 200)'
' \{'
'var response = Lookup.responseText.replace("<!-- Generated by Webspeed: http://www.webspeed.com/", "");'
' response = response.replace("http://www.possenet.org/ --\>", "");'
' response = response.replace(",", "");'
' response = response.split("| ");'
'var dum1 = response[1];'
'response[0] = "";'
'response[1] = "";'
'document.getElementById("CustName").value = dum1;'
' \}' /* if status == 200 */
' \}' /* if readyState == 4 */
' else' /* Request failed */
' \{'
'document.getElementById("CustName").value = "New1";'
' \}' /* else failed */
'\}' /* function showcustname */

'</script>'
' </head>'
' <body>'
.
phtml =
' <form action="' +
HostURL + AppURL + vWebObject + 'ProgID=2910&SID=' + vSID +
'" method="post"' + ' onsubmit="return true;">'
'<table border=1 width="100%">'
INPUT:
pHtml = pHtml +
' <tr id="InputFields1">'
' <td>'
' <font color="#191970"><b>Customer No:</b></font>'
' </td>'
' <td>'
'<input onchange="getcustname()" type="text" name="CustNo" size="12" value="' + vCustNo + '">'
' </td>'
' <td>'
' <font color="#191970"><b>Name:</b></font>'
' </td>'
' <td>'
'<input id="CustName" type="text" name="CustName" size="33" value="' + vCustName + '">'
' </td>'
' </tr>'
+ CR.

/******************************************************************************/
/* Output the "Event" buttons on the bottom of the webpage */
/******************************************************************************/
phtml =
' <input type="submit" name="Event" value="Save" '
+ '&PassRecid=' + string(vPassRecid) + '>'
' </table>'
' </form>' /* FORM CLOSE-OUT */
.
/* Footer */
pHtml = pHtml +
' </body>'
''
'</html>'
+ CR.
/************************** End Of op/e-chklst2.p

***************************************************************************

This is the lookup routine:

def var vCustNo as char no-undo.

{src/web2/wrap-cgi.i}

assign
vCustNo = get-value("CustNo")
.

find customer no-lock
where customer.cust-no = vCustno
no-error.

/******************************************************************************/
/* WebSpeed WORK AROUND */
/* -------------------- */
/* Since webspeed likes to prepend it's own header IN FRONT OF the actual */
/* values it returns, we prepend a pipe symbol to our data (|) so that the */
/* calling JavaScripts can then "split" the return ON the pipe symbol, AND... */
/* more importantly, throw away all of the rest ! (otherwise, if we stuff */
/* EVERYTHING returned by WebSpeed into a page display, we get a blank page */
/* containing only the return value. (BUT, having Webspeed's header when you */
/* view the source on this all blank page !) */
/******************************************************************************/

if avail customer then
phtml = "| " + customer.name.
else
phtml = "| New".

/* {&OUT} pHtml skip. */
{&OUT} pHtml.
pHtml = ''.

/*********************** End of /op/lku_custname.p

***************************************************************************
And this is the "just" of the "dispatch" routine,
which invokes the lookup routine.

/* All validations passed, run requested procedure */
run value(vProgName) (input wRequest,
input vDebug,
input vLogfile,
output vOutString,
output vResult
).

if vOutString <> ''
then
{&OUT}
vOutString
. /* end &OUT */

vOutString = ''.

END PROCEDURE. /* process-web-request */
***************************************************************************
/************************** End of d_ajax.p
tbaxter99
Contributor
 
Posts: 2
Joined: Wed Nov 21, 2007 8:56 pm


Return to WebSpeed

Who is online

Users browsing this forum: No registered users and 1 guest

cron