Jump to content

Execute javascript + callback


zanona

Recommended Posts

I need to execute a java script code and get its return as soon as the exception ends. Is it possible to do this action?

I can already execute the javascript using the code below, but I need to get its return as soon as it finishes executing.

   with JSInterface do WebForm of TUniForm
   begin
     JSCallGlobal('criaSessaoIdJson', ['']);
   end;

Link to comment
Share on other sites

2 hours ago, zanona said:

I need to execute a java script code and get its return as soon as the exception ends. Is it possible to do this action?

I can already execute the javascript using the code below, but I need to get its return as soon as it finishes executing.

   with JSInterface do WebForm of TUniForm
   begin
     JSCallGlobal('criaSessaoIdJson', ['']);
   end;

You need to send an ajaxRequest to server in your custom function when your process done.

for example

ajaxRequest (sender, '_done', []);

 

  • Like 1
Link to comment
Share on other sites

15 minutes ago, Hayri ASLAN said:

Você precisa enviar um ajaxRequest para o servidor em sua função personalizada quando seu processo terminar.

por exemplo

ajaxRequest (sender, '_done', []);

 

Would you have an example to help with understanding? Would this ajaxRequest be a function?

Link to comment
Share on other sites

Attached is an example, in MainForm.script you may have:

function myFunction() {
  var num = 2 + 3;
  ajaxRequest(MainForm.form, ['callback'], { res: num} );
}

And in MainForm:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  uniSession.addJS('myFunction()');
end;

procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
 if sameText(eventname,'callback') then
  begin
    showMessage('Result: '+Params.Values['res']);
  end;
end;

 

ajaxtest.zip

  • Like 2
Link to comment
Share on other sites

On 10/31/2023 at 9:50 PM, Ron said:

Anexado é um exemplo, em MainForm.script você pode ter:

function myFunction() {
  var num = 2 + 3;
  ajaxRequest(MainForm.form, ['callback'], { res: num} );
}

E no MainForm:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  uniSession.addJS('myFunction()');
end;

procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
 if sameText(eventname,'callback') then
  begin
    showMessage('Result: '+Params.Values['res']);
  end;
end;

 

AjaxTest.zipBuscando informações...

Thanks for the help! But what would it look like to call a function that is inside my test.js file?

The function would be

function StartTransaction(type, function, vpsJson)
{
}

In the end I would get your return!

Link to comment
Share on other sites

  • 1 month later...

On ajaxRequest and similar subject, this is the main problem:
And I said it many times. Syntax, scope , using in uniurlframe, unihtmlframe, reference  parent window, just window, calling from external js file, inside html code, header or foot at the html, main form script, inframe inside another inframe... very annoying. 
And more, inject in pascal to convert to client or server side. A lot of function/lib/jscode I got, with exactly the same syntax does not work. Further more, JS is really a shit language, no wonder, so many "versions", frameworks, jquery, messed up scopes, var "inferno", type casting inferno, hard to debug code and every day some one come up with the "new holly solution" that nobody, but nobody came up about it the last 15 years or so. Not even talk about Ext.JS huge learning curve. 

And above all, the "browser cache devil" that I really never heard of it before play with JS...  and no documentation of the above topics.
 

Link to comment
Share on other sites

Really not blaming uniGUI , "au contraire, monsieur", but if you want to do really advanced stuff, got a lot of wall to break thru.

That's why I always advocated for a "bared naked to the bones" uniGUI with just the basic to session management that will easily allow binding to DMs (aka connect to DB and vcl components). That is the same problem that all other frameworks for Delphi fail, I mean, Intraweb and TMS Webcore. The first, became a old and crippled monster with a lot of nonsensical lose ends , the other is an uniGUI in steroids: get things done with tons of comps and a huge bill. 

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...