Problem with APLJax

MiServer is Dyalog's APL-based web development framework

Problem with APLJax

Postby ray on Thu Nov 17, 2016 1:38 am


I am having a problem running with the "production" version of MiServer 3.
(Since Eastbourne, I have been using BETA versions of MiServer 3.)

So, I have converted my ANTS code to us "Compose" rather than "Render", and that is working well up to the point when I expect the callback function "APLJax" to be triggered by a timer.

However, whenever the timer is triggered, instead of running "APLJax", the "Compose" function is being re-run.

I suspect the problem might be in the JScript I am using.

The APL that writes the JScript that has been working up to now includes the following "ajax" call
Code: Select all
r,←⊂'     $.ajax('
 r,←⊂'     {'
 r,←⊂'          url      : "/hex.dyalog",'
 r,←⊂'          cache    : false,'
 r,←⊂'          type     : "POST",'
 r,←⊂'          dataType : "json",'
 r,←⊂'          complete : poll,'
 r,←⊂'          success  : function(obj)'
 r,←⊂'          {'
 r,←⊂'              $.each(obj,function(i,d)'
 r,←⊂'              {'
 r,←⊂'                APLJaxReturn(obj);'
 r,←⊂'              });'         ⍝ each
 r,←⊂'          }'               ⍝ success
 r,←⊂'     });'                  ⍝ ajax

Have you any suggestions to what has been changed (since April 2016) that might be causing my problem?
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
Posts: 182
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: Problem with APLJax

Postby Brian|Dyalog on Thu Nov 17, 2016 4:57 pm

Hi Ray!

Yeah, we needed to modify some of the APLJax processing. Previously we were treating any request that was an XMLHttpRequest as an APLJax call, but in an environment where there may be other XLMHttpRequests that were not intended to be APLJax calls, MiServer would inappropriately handle them. So, we needed to add a special header in the ajax() call to positively identify the request as an APLJax request. So you need to modify your code as follows (or use MiServer's _.Handler)...
      r,←⊂'     $.ajax('
r,←⊂' {'
r,←⊂' url : "/hex.dyalog",'
r,←⊂' cache : false,'
r,←⊂' type : "POST",'
r,←⊂' headers : {"isAPLJax" : "true"},'
r,←⊂' dataType : "json",'
r,←⊂' complete : poll,'
r,←⊂' success : function(obj)'
r,←⊂' {'
r,←⊂' $.each(obj,function(i,d)'
r,←⊂' {'
r,←⊂' APLJaxReturn(obj);'
r,←⊂' });' ⍝ each
r,←⊂' }' ⍝ success
r,←⊂' });' ⍝ ajax

However, in looking at that, I think I may want to update how we do this to use the JavaScript true constant, and not the string "true". If we do that, I'll let you know; it shouldn't impact many MiServer users as I suspect very few are writing their own ajax calls.

Also, another way to insert constant code (assuming your page is based on the MiPage class) is to use ScriptFollows which reads the block of subsequent contiguous comments as a character constant.
⍝ $.ajax(
⍝ {
⍝ url : "/hex.dyalog",
⍝ cache : false,
⍝ type : "POST",
⍝ headers : {"isAPLJax" : "true"},
⍝ dataType : "json",
⍝ complete : poll,
⍝ success : function(obj)
⍝ {
⍝ $.each(obj,function(i,d)
⍝ {
⍝ APLJaxReturn(obj);
⍝ }); //each
⍝ } //success
⍝ }); //ajax

I hope this helps!
User avatar
Posts: 109
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: Problem with APLJax

Postby ray on Wed Nov 23, 2016 2:10 am

Hi Brian,

Adding the extra line
Code: Select all
headers  : {"isAPLJax" : "true"},

in my JavaScript did the trick, and my Ants are once again marching across my MiServer page again!

After I originally wrote this code, I became aware if the ScriptFollows trick, but have not (as yet) bothered to re-write Ants using this feature. There are many such features that are now available under MiServer 3, that were not available/documented then.

Thanks again for the feedback, and for all the help you have given me in the past, not to mention all the hard work you have put into MiServer.

Ray Cannon
Please excuse any smelling pisstakes.
User avatar
Posts: 182
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Return to MiServer

Who is online

Users browsing this forum: No registered users and 1 guest