send data with post method

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!

send data with post method

Postby Otto » Tue Sep 17, 2019 7:13 am

Dear Antonio I have a function attached to a button and I want to send data to the calling program.
function nextstep(){
var id;
var TableData = new Array();
$('#sampleTbl tr').each( function(row, tr){
$id = parseInt($(tr).find('td:eq(0)').text(), 10) + 1; TableData = TableData
+ "Task No."+ $(tr).find('td:eq(0)').text() + ': ' // Task No.
+ aArtNr[$id] + ' ' // Description
+ '\n';
});
window.location ="/booking_new/zusatz.prg?buchung=" + TableData ;
}
This is working and I get the data with ? STRTRAN(AP_Args(), "%20", " ")
How can I send these data that I can get it with hPairs := AP_PostPairs()
--------------------------------------------------------------------------------------
Antonio Linares 08:49 Uhr
use POST instead of GET

Otto 08:50 Uhr
can you please tell me where
I think this comes from js window.location ="/booking_new/zusatz.prg?buchung=" + TableData ;
do I have to make a form first
--------------------------------------------------------------------------------------

Antonio Linares 08:55 Uhr
$.post( "zusatz.prg", { one: "one", two: "two", three: "three", whatever: 123 } )
.done( function( data ) { console.log( 'DONE', data ); $( cResultId ).html( data ); } )
.fail( function( data ) { console.log( 'ERROR', data ); } );

second parameter is a JS object (JSON notation)

one: "one" etc are the pairs that you will get from AP_Postairs()
No need to create a form
You can send whatever you want just using a JS object
(JSON means: JS object notation)

in my case this is an array. can I send an array, too.
Antonio Linares 08:57 Uhr
yes

do you know it there is a sample in sample folder
Antonio Linares 08:58 Uhr
{ values: [ one: "one", two: "two", three: "three" ] }
arrays use [ ... ]
can be nested as in Harbour
always think in JSON terms
whatever data you need to move around... use JSON
$.post() sends the data as POST
________________________________________
Neue Nachrichten
Charly 09:03 Uhr
You can also try $.get(), the same but via GET
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6064
Joined: Fri Oct 07, 2005 7:07 pm

Re: send data with post method

Postby Otto » Wed Sep 18, 2019 5:39 am

Andreu Botella 21:11 Uhr
@Otto The Jquery function $.post is an AJAX function, it doesn't reload the page.
If you want to get the result of the POST call, you have to add a listener callback and then do whatever with the result. (bearbeitet)
https://api.jquery.com/jQuery.post/
The signature is
jQuery.post( url [, data ] [, success ] [, dataType ] )
(jQuery.post is the same thing as $.post) (bearbeitet)
so you have to call it like this:
$.post(
"postpairs.prg",
{/* any POST data you want to pass to the prg */},
function (data) {
alert(data) // or something else
}
)
(bearbeitet)
Hope that helps
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6064
Joined: Fri Oct 07, 2005 7:07 pm

Re: send data with post method

Postby Otto » Wed Sep 18, 2019 8:36 am

Antonio Linares 08:49 Uhr
from the callback you jump to another page
$.post(
"postpairs.prg",
{/* any POST data you want to pass to the prg */},
function (data) {
location.href = "web page to go to";
}
)
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6064
Joined: Fri Oct 07, 2005 7:07 pm

Re: send data with post method

Postby Otto » Thu Sep 19, 2019 7:00 am

Dear Antonio,
thank you. Now I have a working sample with $.post()

There is a space in <s cript> otherwie you can not post the code here.

Best regards
Otto


post.prg
Code: Select all  Expand view

function Main()
 
  TEMPLATE
  <html>
  <head>
    <s cript src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></s cript>
    <s cript>
      $(document).ready(function(){
       
        $("button").click(function(){
         
          $.post(
          "postpairstxt.prg",
          { one: "one", two: "two", three: "three", whatever: 123 } ,
          function (data) {
            location.href = "https://winhotel.space/modharbour_samples/posttest2.prg";
          }
          );
        } );
       
      });
     
    </s cript>
  </head>
  <body>
   
    <button>Send an HTTP POST request to a page and from the callback you jump to another page</button>
   
  </body>
  </html>
 
  ENDTEXT
 
return nil


 


reqest.prg
Code: Select all  Expand view

REQUEST DBFCDX
REQUEST DBFFPT
function Main()

   local hPairs := AP_PostPairs()
   local cLog
   
   cLog := ValToChar( hPairs )

   USE ( hb_GetEnv( "PRGPATH" ) + "/logfile" ) SHARED NEW

   APPEND BLANK

   if RLock()
    logfile->datum    := Date()
    logfile->text    := cLog
    logfile->user_time    := time()
    DbUnLock()
   endif

   USE

return nil


INIT PROCEDURE PrgInit
   
   SET CENTURY ON
   SET EPOCH TO YEAR(DATE())-98
   
   SET DELETED ON
   SET EXCLUSIVE OFF
   
   REQUEST HB_Lang_DE
   
   HB_LangSelect("DE")
   
   SET DATE TO GERMAN
   
   rddsetdefault( "DBFCDX" )
   
   EXTERN DESCEND
   
RETURN

 


DBF file

Code: Select all  Expand view

local aFields := { { "TEXT", "C", 200, 0 },;
                   { "DATUM", "D", 8, 0 },;
                   { "USER_TIME", "C", 25, 0 },;
                   { "CODE", "C", 4, 0 } }

DbCreate( "myfile.dbf", aFields, "DBFCDX" )

USE myfile.dbf NEW VIA "DBFCDX"
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6064
Joined: Fri Oct 07, 2005 7:07 pm


Return to mod_harbour

Who is online

Users browsing this forum: No registered users and 1 guest