value not passed to request handler from java snippet

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}";"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;"came inside app" + valuetoday);             if ("POST".equals(request.getHttpServletRequest().getMethod())) {                 try {   "came inside POST");                     ISession oldSession = this.getSessionFromRequest(request);                     String loginToken = request.getParameter("loginToken");   "login token" +loginToken);                     if (loginToken != null) {   "came inside login Token"); } } } } But this loginToken is coming empty here. Please tell me where the issue is. Java script snippet screen shots:
3 answers

As you stated, the 


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 () {



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};


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.