SantoshGnostice Posted October 17, 2017 Share Posted October 17, 2017 I am looking for server side method which can invoke a JavaScript function that takes a callback and later asynchronously calls this callback which should result in a server-side call. Basically an async version of existing JSCall method which can take an anonymous function or a delphi callback. Is there such a method already present? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted October 17, 2017 Share Posted October 17, 2017 Hi, If I understand you correctly, you can use ajaxRequest (client side) and OnAjaxEvent (server side) You can find a lot of posts on this topic on the forum Best regards, Quote Link to comment Share on other sites More sharing options...
SantoshGnostice Posted October 17, 2017 Author Share Posted October 17, 2017 A simple example of what I am looking for: Server-side: procedure CallBack(AResult: string); begin // Control comes here after timeout end; JSAsyncCall('method', CallBack); Client-side (JS): method: function(callback) { setTimeout(callback, 1000, 'result'); } I could use ajax to achieve this but I'd have to maintain a mapping on the server of all the callback functions and call them appropriately when the message arrives from the client. I am sure UniGUI must have solved this problem already - so I was looking to see if the framework has something I can use to achieve this. Quote Link to comment Share on other sites More sharing options...
SantoshGnostice Posted October 24, 2017 Author Share Posted October 24, 2017 Hi Just checking if there is anything to use for the above situation? Calling an async JS function from the server and getting response from it? Quote Link to comment Share on other sites More sharing options...
SantoshGnostice Posted October 25, 2017 Author Share Posted October 25, 2017 I have found an example implementation in UniGUI that may suit what I am looking for. The method "uniGUIDialogs.Prompt" takes a callback function which is called from the client-side once the user dismisses the dialog. Is there something similar which we can use when developing a custom component? How is the the Delphi callback procedure linked to the client-side callback? Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted October 25, 2017 Administrators Share Posted October 25, 2017 You can achieve this by calling a JS method using server side method JSCall() and on client side your method will cast an ajaxRequest() call which will be handled in OnAjaxEvent Delphi handler. Quote Link to comment Share on other sites More sharing options...
SantoshGnostice Posted October 26, 2017 Author Share Posted October 26, 2017 Yes, thank you. I have started working in that direction. 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.