0

This might sound a bit crazy but is there a way to call a procedure synchronously?

I am using MobileFirst Platform Foundation 7.1 and I am writing an app in javascript for the browser. I usually call my javascript adapter by:

WL.Client.invokeProcedure({
    adapter: 'MyAdapter',
    procedure: 'myProcedureName',
    parameters: []
}).then(function(res) {
   ...
});

But in this particular case I need to open another window after getting some data from the server. Since browsers will block windows when they come from async ajax my new windows does never open.

A way to solve this would be to do the ajax request sync. Is this possible with WL.Client apis? Is there a way for constructing the request manually so I can set the sync ajax flag by myself?

PS: in my case doing sync ajax request would work nice since I show a "Loading ..." view on top of everything to prevent user interaction while the request is being done.

Community
  • 1
  • 1
nacho4d
  • 43,720
  • 45
  • 157
  • 240

1 Answers1

1

WL.Client.connect() does not support .then. Additionally, starting 7.0 you should use the REST API method WLResourceRequest: https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/server-side-development-category/

Lastly, you could just put the second request in the onSuccess callback of the first...

Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • Now I am using WL.Client.connect() without `.then` and I think so far it works ok. I cannot use the REST WLResourceRequest since my app is for the browser and I am using Javascript adapters. I wanted to do just a simple synchronous ajax call (no need to modify WL.Client.connect stuff) but apparently is not possible right? – nacho4d Oct 22 '15 at 04:42
  • After a long time... Thanks Idan, I have realized there was no need of doing what I originally wanted (sync request). I realized this was a typical problem of javascript events, so I ended up by opening the window first and firing my request then when the request finishes I fill the new window content as needed. – nacho4d Apr 24 '16 at 13:59