value not passed to request handler from java snippet

0
Hi,  am using below java script to call a request handler and sending "loginToken" value as param, below java script: var xhr = new XMLHttpRequest(); var url = mx.appUrl + "autologin/"; var params = "loginToken=${loginToken}"; xhr.open("POST",url,true); xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); xhr.send(params); location.reload();   Request handler:   private static final String XAS_ID = "XASID";     protected static ILogNode AUTOLOGINLOGGER = Core.getLogger("AutoLogin");     class AutoLoginHandler extends RequestHandler {         @Override         public void processRequest(IMxRuntimeRequest request, IMxRuntimeResponse response, String arg2)                 throws Exception {         String valuetoday = arg2;         AUTOLOGINLOGGER.info("came inside app" + valuetoday);             if ("POST".equals(request.getHttpServletRequest().getMethod())) {                 try {             AUTOLOGINLOGGER.info("came inside POST");                     ISession oldSession = this.getSessionFromRequest(request);                     String loginToken = request.getParameter("loginToken");             AUTOLOGINLOGGER.info("login token" +loginToken);                     if (loginToken != null) {             AUTOLOGINLOGGER.info("came inside login Token"); } } } } But this loginToken is coming empty here. Please tell me where the issue is. Java script snippet screen shots:
asked
3 answers
1

As you stated, the 

location.reload()

will be triggered even before the data is sent, because of the asynchronous behavior of Javascript. The proper way to reload this would be to add it as an event listener:

xhr.addEventListener("load", function () {
    location.reload();
});

 

answered
0

I am not a javascript specialist but I used something similar and it worked ok. 

Looking at the way you have inserted the param I would suggest you try this:

var params = "loginToken=" + ${loginToken};

answered
0

Data was not sent because of location.reload();. This statement is refreshing and removing data. I deleted this statement and did a refresh via microflow after js execution. This solved the issue. 

answered