Page 1 of 1

Call an RPG program with Ajax

Posted: Tue Nov 27, 2012 5:33 am
by kaw
I would call my RPG program that I created with green screens using Ajax container. Where to place my PGM and what I have to put URL to the program can be seen?

Thank you for your help!

Re: Call an RPG program with Ajax

Posted: Tue Nov 27, 2012 6:51 pm
by Scott Klement
What the AjaxContainer does, essentially, is call a URL (GET request) and put the output in the box. This fires when the screen is rendered.

For example, in the designer, drag an AjaxContainer to your screen. Set the "ajax url" property to something like "/example/myscript.php". (Assuming your ProfoundUI instance is set up to work with PHP). This will run the myscript.php script, and the output will be displayed in the AjaxContainer box.

It can work with any URL, as long as that URL is on the same server/port. To prevent cross-site scripting, browsers do not allow Ajax requests to other URLs (that are not on the same server/port.)

However, we provide a similar widget named "iframe" that does allow requests to another server/port, if that's useful to you.

Re: Call an RPG program with Ajax

Posted: Tue Nov 27, 2012 6:57 pm
by Scott Klement
Err... sorry, I just re-read your message and noticed that you want the Ajax Container to call an RPG program that outputs a green-screen?

That's not going to work. Ajax is for calling web applications, not green-screen programs. The program you call with an AjaxContainer (or an iframe, for that matter) needs to output HTML.

Though, I guess it might be possible to make Genie convert your screen to HTML and then embed that in an iframe? But this seems rather convoluted, especially since you're already in the Genie environment. Why not just display the output directly?

Can you explain a bit more of what you're trying to accomplish -- there may be a better/easier way.

Thanks!

Re: Call an RPG program with Ajax

Posted: Wed Nov 28, 2012 5:17 am
by kaw
What I would do is as shown in the example:
js: "/ genie / getData.pgm? custid =" + get ("I_5_6");
I call PGM and displays the result in the AjaxContainer.

Re: Call an RPG program with Ajax

Posted: Wed Nov 28, 2012 1:01 pm
by Scott Klement
Okay, now I see how you're building the URL to your program.

But, I'm afraid, I'm a little confused, here. I'm going to need your help to understand a few things:
  • What are you trying to achieve? ...and why?
  • What is the /genie/ directory used for? A ScriptAlias? Can you tell me more about how that works? Or post the keywords from the Apache config?
  • What does the "getData" program do?
  • How does the getData program write it's output? As I said before, this needs to output data in HTML (not output green screens.)

Re: Call an RPG program with Ajax

Posted: Thu Nov 29, 2012 5:29 am
by kaw
This is an example that I saw in the documentation http://www.profoundlogic.com/docs/displ ... +Container and would like to make such a.
My problem is where to place the program RGP (getData.pgm) that I am creating.
In my program I put a "Hello wordl" simply, without passing parameters to the test.

Re: Call an RPG program with Ajax

Posted: Thu Nov 29, 2012 10:03 am
by kaw
I'll be back with more accuracy to my question!
I'm in Genie. I would like to call an RPG program, passing as parameter an field of screen by clicking a button and the program I revisit a "HELLE WORLD".
1) Should I install CGI Dev2?
2) If I put my RPG program in the library "toto", which directive should I put in my apache http.conf of seveur?
3) Do you have a small example of such a program?

Thank you!

Re: Call an RPG program with Ajax

Posted: Thu Nov 29, 2012 10:34 am
by Scott Klement
1) It'll work with CGIDEV2 if that's the method you prefer. It'll also work with RPGsp (our tool that's similar to CGIDEV2, but more powerful, and a commercial product) or with plain CGI, or PHP or Java or ... well, anything else, really.

2) The idea behind the Apache directive is to create an "alias" so that a string that's in the URL points to a library. So you could add the following to your httpd.conf (Apache config file):

Code: Select all

ScriptAlias /kaw /qsys.lib/toto.lib
<Directory /qsys.lib/toto.lib>
   Order Allow,Deny
   Allow from All
</Directory>
When someone sends a URL like http://YOUR-SERVER/kaw/MYRPG.pgm it will run the program named MYRPG in the library named TOTO. It knows the library is TOTO because "/kaw" is an alias for '/QSYS.LIB/TOTO.LIB" (Which is the IFS syntax for the TOTO library)

3) Do you know which environment you'll be coding this in? Maybe CGIDEV2? Or PHP? Java? Lua? Python? RPGsp? Perl? Since you can run any URL that outputs data, I'm a bit overwhemed by all of the possibilities, here.