zanona Posted October 31, 2023 Share Posted October 31, 2023 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; Quote Link to comment Share on other sites More sharing options...
Hayri ASLAN Posted October 31, 2023 Share Posted October 31, 2023 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', []); 1 Quote Link to comment Share on other sites More sharing options...
zanona Posted October 31, 2023 Author Share Posted October 31, 2023 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? Quote Link to comment Share on other sites More sharing options...
Ron Posted November 1, 2023 Share Posted November 1, 2023 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 2 Quote Link to comment Share on other sites More sharing options...
zanona Posted November 2, 2023 Author Share Posted November 2, 2023 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! Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 2, 2023 Share Posted November 2, 2023 Hello, Please describe your task and case in detail. Quote Link to comment Share on other sites More sharing options...
zanona Posted November 2, 2023 Author Share Posted November 2, 2023 1 hour ago, Sherzod said: Hello, Please describe your task and case in detail. Below is the example file! Note that it makes a request to the javascript agentCliSiTef.js I need to get the return from the criaSessao function that is inside the agentCliSiTef.js file. It would be possible? test javascript.zip Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 2, 2023 Share Posted November 2, 2023 I haven't looked at your test case yet. But perhaps you will also find this post useful: Quote Link to comment Share on other sites More sharing options...
zanona Posted November 2, 2023 Author Share Posted November 2, 2023 6 hours ago, Sherzod said: Eu ainda não olhei para o seu caso de teste. Mas talvez você também ache este post útil: Thank you for your help, I saw your example but I still couldn't do what I needed! Quote Link to comment Share on other sites More sharing options...
Ron Posted November 2, 2023 Share Posted November 2, 2023 You use a JS function to call the server, to set some session data? Why not do that directly in the code? Anyway, attached is your example, with the JS file and mainForm code modified to use the ajaxRequest function. test javascript.zip 1 Quote Link to comment Share on other sites More sharing options...
zanona Posted November 2, 2023 Author Share Posted November 2, 2023 Thanks a lot for the help! That's what I needed :D Quote Link to comment Share on other sites More sharing options...
Fred Montier Posted December 12, 2023 Share Posted December 12, 2023 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. Quote Link to comment Share on other sites More sharing options...
Fred Montier Posted December 12, 2023 Share Posted December 12, 2023 Someday, when I got my farm and retire, I'll rise two pigs and will name them: AJAX and REQUEST ! Just to see the mess they will do when I call. 3 Quote Link to comment Share on other sites More sharing options...
Fred Montier Posted December 12, 2023 Share Posted December 12, 2023 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. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.