Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ajaxCall in dedicated web worker thread
#1
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
Reply
#2
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
Reply
#3
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...
Reply
#4
Hi Alexandre,

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

Regards
Juergen


Attached Files
.zip   ChatDemo.zip (Size: 12.98 KB / Downloads: 1)
Reply
#5
Fixed class definition bug


Attached Files
.zip   ChatDemo.zip (Size: 13 KB / Downloads: 8)
Reply
#6
I'll have a look and let you know.

Thanks for creating the test case.
Reply
#7
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?
Reply
#8
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)