Atozed Forums
ajaxCall in dedicated web worker thread - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: ajaxCall in dedicated web worker thread (/thread-2644.html)



ajaxCall in dedicated web worker thread - JuergenS - 02-19-2022

Hi,

when trying to use an ajaxCall in a dedicated web worker thread I get the following error:
ReferenceError: ajaxCall is not defined
The call works in the main thread.

Is this behavior correct?


Regards
Juergen


RE: ajaxCall in dedicated web worker thread - JuergenS - 02-23-2022

The following problem occurred in the main thread when testing the AJAX callback TIWCallbackProc2:

TIWCallbackProc2 = reference to procedure (aParams: TStrings; out aResult: string);

ajaxCall("Multiply", "&x=5&y=10", false, function(response) {alert("Result is: " + response);});

In the above example, the callback function receives 2 parameters named x and y, and multiply them.
The result is put into aResult parameter (which is an out parameter).
The difference here compared to old versions is that aResult string is returned to the browser as is, i.e.
the response will contain a string representing the result of the multiplication of x by y only, nothing else.
This makes much easier to interface with existing JavaScript libraries which expect specific responses (e.g. JSON strings).

In fact, when a valid result is returned from the server, the browser only gets that one string, and that's really easy to deal with.
However, if no valid result is provided by the server, the browser receives the following output:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><response>

<update>

</update>

<submit>/</submit>

<trackid>29</trackid></response>

Since something is always delivered, the evaluation of the result is not that easy.


The following problem occurred in the main thread when testing the AJAX callback TIWCallbackProc3:

TIWCallbackProc3 = reference to procedure (aParams: TStrings; out aResult: string; out aHandled: Boolean)

The forth type of callback (TIWCallbackProc3) is the most flexible one.
It allows you to set the result directly using variable aResult (as above) or still use TIWApplication.CallbackResponse object (as in IW 15.0), or yet,
bypass the response completely setting aHandled parameter to True.
Setting aHandled to True means that the user code is responsible for creating the reponse.
In this case, IntraWeb will skip the execution of callback response code completely.

If the parameter aHandled = true is set on the server, you get a message box with the error message: "Uninitialized reply",,
which can be prevented by the following call:

UserSession()->WebApplication->Response->Code = 200;

However, the AJAX response function is still called, but with an empty response!


C++Builder 11.0
Intraweb 15.2.50


RE: ajaxCall in dedicated web worker thread - Alexandre Machado - 02-24-2022

Can you please provide a simple test case showing that (either Delphi or C++)? It would be much simpler to understand exactly what you are trying to achieve...


RE: ajaxCall in dedicated web worker thread - JuergenS - 02-24-2022

Hi Alexandre,

this is a simple test case for the 32 bit classic c compiler.

Regards
Juergen


RE: ajaxCall in dedicated web worker thread - JuergenS - 02-25-2022

Fixed class definition bug


RE: ajaxCall in dedicated web worker thread - Alexandre Machado - 03-02-2022

I'll have a look and let you know.

Thanks for creating the test case.


RE: ajaxCall in dedicated web worker thread - Alexandre Machado - 03-14-2022

Hi there

I tested your sample application and it worked fine (the exact same app, in C++)

You are setting the result code to 200 but not writing anything to the response. If you are handling it yourself you need to actually handle it with your own code.

IntraWeb doesn't know what you expect as a response, so you need to write to the response whatever you expect it to be.

What your JavaScript code expects as a response to this call?


RE: ajaxCall in dedicated web worker thread - JuergenS - 03-14-2022

Hi Alexandre,

yes the example with TIWCallbackProc3 works now, but it took me a while to figure out how to do it.
It would certainly be helpful if the documentation included hints.
Actually I wanted to use the variant with TIWCallbackProc2.
But here if the result is empty, the AJAX response function does not return an empty response, but always the specified XML result as the response.

The JavaScript code is included in the example.

Regards

JuergenS