Question Webspeed Newbie!

stokefc22

Member
Hi Guys,

I'm a total newbie to webspeed and all things web development so please go easy :)....

Having spent many years developing openedge event driven stuff I think I maybe struggling with a different approach!! I've inherited the maintenance of a simplish website that we have and unfortunately there is no one to tap for information so I'm hoping one of you guys can set me straight.

I have a field on a webpage and on entering a value I want to go off, query a progress db and populate another field on the same webpage with a certain value from the db...

I have this.
HTML:
<input type="text" class="standard" name="customer1" value="`b-data.setting[11]`" style="width:50px;" maxlength="5" `lv-dis2` TABINDEX=`INDEX(gv-taborder,"customer1")` OnChange="getCurr()">

and firstly I was thinking I could put something in the getCurr function but this is javascript(right??) so I'm assuming you can't add progress code in a javascript funtion..

Can someone advise how this kind of thing is achieved or point me in the right direction please?

Many thanks
 

lee.bourne

Member
You're right that getCurr is going to be JavaScript. What you want to investigate is AJAX: http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

Using AJAX you can make a call to a Progress Webspeed app or Webservice to retrieve the result as XML or JSON for you to parse and deal with as you like. Alternatively you could just use document.forms[0].submit() and this will send the whole page (form) to the Progress side and you can rewrite the page accordingly.

The first approach is neater and provides a better user experience as it doesn't require a page refresh. The second it 10 times easier to implement.

Good luck,

Lee
 

stokefc22

Member
Hi Lee, thanks for your invaluable information. I took it as a challenge to try and go down the Ajax route and so we have the following.....

The function getcurr now looks like
Code:
function getCurr()
{
    var xmlHttp;
    var custNum;
    var jsonObject;
    //get custnum from form entry
    custNum = document.FrmMain.customer1.value;
    //Create an XMLHttpRequest Object
    // code for IE7+, Firefox, Chrome, Opera, Safari
    if (window.XMLHttpRequest)
        {xmlhttp=new XMLHttpRequest();}
    else    // code for IE6, IE5
        {xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
    //triggered every time the readyState changes
    xmlhttp.onreadystatechange=function()
    {
        // readyState values
        // 0 = request not initialised
        // 1 = server connection established
        // 2 = request recieved
        // 3 = processing request
        // 4 = request finished and response ready
        // status values
        // 200 = ok
        // 404 = page not found
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            jsonObject= xmlhttp.responseText;
            alert(jsonObject.name);
            //document.getElementById("currCode").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","getCurrDets.html",true);
    xmlhttp.send();
}

I created an HTML file (not sure this is the best way, in my mind I wanted a .p but the compiler doesn't like the speed script syntax..).

GetCurrDets.html is as follows
Code:
<script language="speedscript">
    output-content-type('application/json').
    find first  abbey.country no-lock no-error.
    {&out}
        '~{"name":"' abbey.country.Countrycode '~"}'.
</script>

...very simple at the mo will need to pass in a variable etc later but thought I'd get it going like this for now.

Now for the problem!! As you can see the jsonObject variable holds the string returned from the HTML file, now if I simply display jsonObject in the alert it displays "name":"au" as expected but if I try to reference the name as in the example it's just blank.

Is there something obvious you can see that I have missed?

Again thanks for the help and hope you can help again :)
 

lee.bourne

Member
Hi,

I probably confused the issue by mentioning JSON. All (modern) browsers will support XML but you'd have to use something like jQuery to parse JSON. Progress also supports XML better too, although the later versions of Progress are pretty good at JSON too now.

If you switch to XML you should find that everything works just fine.

Also, rather than use SpeedScript I'd recommend getting CGI Wrappers working. Using the AppBuilder just go to File, New, CGI Wrapper. It'll set you up with an empty template for outputting to the web stream. It'll create you 2 procedures, one for outputting the http header / mime type and another for the content. By all means hand craft the XML to get your proof of concept working but after that definitely look at the support for XML that Progress offers, it'll make your job loads easier.

Have fun,

Lee
 

stokefc22

Member
Thanks Lee,

I've finally managed to get something going now, although I'm thinking I may not be returning the xml string in the correct manner as the reponseXml just seems to return null.

I got round it by using the responseText and then converting it using parseFromString...

Our appbuilder has been modified so there is no option for creating a CGI wrapper so I'll have to look into that.

Thanks again for your help
 

lee.bourne

Member
You'll probably find that if you're still using SpeedScript then the content type is set as text/html rather than using application/xml. I've attached a blank cgi wrapper for you to start with. Hopefully you already have src/web2/wrap-cgi.i on your system somewhere.

Glad you got it working.

Regards,

Lee
 

Attachments

  • cgi_wrapper.p
    6.3 KB · Views: 23

stokefc22

Member
Lee, you are a star!!

It was obviously something to do with the speedscript.. I've used the cgi wrapper template and it now works wonderfully!!

Thanks again for all your help.
 
Top