Page 1 of 1
Simple Ajax URL Question
Posted: Mon Dec 01, 2014 1:05 pm
by negley
I have a very basic question about ajax.
I have a program called XYZ in library ABC. How does that translate into the ajax url?
I assume it would be:
ajax({
url: "XYZ.pgm",
params: {
p1: "123"
},
method: "post",
async: true
});
Does my program need to be setup in any other file, sort of like PUIMAPP for universal?
Re: Simple Ajax URL Question
Posted: Mon Dec 01, 2014 4:02 pm
by Scott Klement
Is this ajax() call to a program made with the Universal handler? If so, then yes, you need to make sure it's set up in the PUIMAPP file. And the URL would be http://your-server:port/profoundui/universal/theurl -- where "theurl" corresponds to what you put for the URL parameter in puimapp.
If the program is an RPGsp page, then the URL would be http://yourserver:port/rpgsp/yourprogram.pgm
If the program is just a general RPG program written to use CGI in some way, then the URL depends on the ScriptAlias/ScriptAliasMatch directive in your HTTP configuration... this is what tells Apache which objects can be called as programs.
Re: Simple Ajax URL Question
Posted: Mon Dec 01, 2014 4:12 pm
by negley
This is a simple RPG program not utilizing universal.
We do not have the RPGsp package.
I would be interested in the http config method, however it might be overkill.
All i am trying to do is pass a parameter into a simple rpg program so data can be inserted into a file. What i can do is create a ajaxJson and use universal to input the data i need. The returning json can just be a confirmation of entry.
I am doing this in ajax because i am using localStorage when a unit is offline. When the unit reconnects, the localStorage is then looped and the data dumped into my ajax program. I feel that this is the best method.
-Bill
Re: Simple Ajax URL Question
Posted: Mon Dec 01, 2014 4:21 pm
by Scott Klement
I guess by "simple" you mean that you've hand-coded the CGI part of it... this should work fine if you've got the HTTP config set up properly.
You'll need a ScriptAlias (or ScriptAliasMatch) in your Apache config. This serves the dual purpose of telling Apache that a URL points to a program to run (as opposed to the default behavior of an object to download to the browser) as well as telling it how to map the URL to the program on disk.
For example, if you want to make a URL containing /whatsit will always run programs in the COOLLIB library, then you might do this:
Code: Select all
ScriptAlias /whatsit /qsys.lib/coollib.lib
Then if you have a URL like http://server:port/whatsit/example.pgm it would be like doing CALL PGM(COOLLIB/EXAMPLE)
There are many variations on this... for locking a URL to a specific program (instead of allowing everything in a library) or removing the need for the .PGM in the URL, etc... lots of variations depending on what you want to do.
In addition to the ScriptAlias part, you need to make sure that you give Apache permission to run programs in the particular library. That's done with the <Directory> directive and the Order/Allow/Deny directives. For example:
Code: Select all
<Directory /QSYS.LIB/COOLLIB.LIB>
order allow,deny
allow from all
</Directory>
The 'order' line says that Apache shoudl check the allow directives first, and then if there's no match, check the deny directives. (With the default being to deny access.) The 'allow' line says to allow access to this library from all IP addresses, thus enabling access to run your RPG program. Again, there are many variations here... you can require a userid/password, for example, or you can allow certain addresses, or deny certain addresses, etc. It depends on what you want to do.
Re: Simple Ajax URL Question
Posted: Mon Dec 01, 2014 4:40 pm
by negley
Thanks for the reply, good stuff! It makes a lot of sense.