Simple Ajax URL Question

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
negley
Profound User
Posts: 45
Joined: Tue Mar 11, 2014 2:50 pm
First Name: William
Last Name: Negley
Company Name: Utz Quality Foods
Contact:

Simple Ajax URL Question

Post 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?
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Simple Ajax URL Question

Post 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.
negley
Profound User
Posts: 45
Joined: Tue Mar 11, 2014 2:50 pm
First Name: William
Last Name: Negley
Company Name: Utz Quality Foods
Contact:

Re: Simple Ajax URL Question

Post 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
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Simple Ajax URL Question

Post 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.
negley
Profound User
Posts: 45
Joined: Tue Mar 11, 2014 2:50 pm
First Name: William
Last Name: Negley
Company Name: Utz Quality Foods
Contact:

Re: Simple Ajax URL Question

Post by negley »

Thanks for the reply, good stuff! It makes a lot of sense.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests