Question

I want to create an application with front-end HTML + JavaScript and back-end Progress4GL.

I found this documentation: http://communities.progress.com/pcom/docs/DOC-106147 (see Introducing AJAX and Introducing JSON). In the example described it is used GET method when requesting data:

xmlhttp.open("GET", "http://localhost/cgi-bin/cgiip.exe/WService=wsbroker1/getcustomersJSON_param.p?piCustNum="+ custval, true);            
xmlhttp.send();

and on Progress4GL procedure for getting the param it is used get-value("piCustNum").

In my application I want to use POST method. So the request will be, for example:

xmlhttp.open("POST","http://localhost/cgi-bin/cgiip.exe/WService=wsbroker1/getcustomersJSON_param.p",true);
xmlhttp.send("piCustNum=" + custval);

But I don't know how to get the sent param on Progress side. Actually I want to send a stringify JSON.

Can anyone help me with this? Thanks!

Was it helpful?

Solution

If you want to POST JSON data to a webspeed program, check out WEB-CONTEXT:FORM-INPUT or if you post more than 32K, check out WEB-CONTEXT:FORM-LONG-INPUT.

Now... regarding reading the JSON data, it depends on your OpenEdge version. In 10.2B Progress started supporting JSON, however it is very limited, especially if you have little control of how the JSON gets created. Since you are the one creating the JSON data it may work for you. Version 11.1 has much better support JSON including a SAX streaming implementation.

We were on version 10.2 so I had to resort to using this C library to convert the JSON into a CSV file. If you have access to Python on your server it is very easy to convert to a CSV file

OTHER TIPS

For the front-end I'd recommend you to use some library (like jQuery) to handle the ajax's request for you, instead of dealing with the complexity to work with different browsers, etc. You can use jQuery's functions like $.ajax, $.get or $.post to make your requests.

A post to a webspeed page could easily be done like this:

var data = {
  tt_param: [ { id: 1, des: 'Description 1' } ]
}

var params = { data: JSON.stringify(data) }

$.post(
  'http://<domain>/scripts/cgiip.exe/WService=<service>/ajax.p',
  params,
  function (data) {
    alert('returned:' + data);
  },
  'text'
);

And the back-end would receive the JSON string using get-value('data'):

{src/web2/wrap-cgi.i}

def temp-table tt_param no-undo
    field id  as int
    field des as char.

def var lc_param as longchar no-undo.

procedure output-header:
    output-content-type("text/text").
end.

run output-header.

assign lc_param = get-value('data').

temp-table tt_param:read-json('longchar', lc_param).

find first tt_param no-error.

{&OUT} 'Cod: ' tt_param.id ', Des: ' tt_param.des.

It's a good place to start, hope it helps.

Cheers,

There is a library from Node for calling Progress Business Logic dynamically. I hope this would help. node4progress

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top