Pages

Tuesday, January 11, 2011

Triggering lotus script agents and obtaining their response on the XPage using Client side javascript - An XMLHTTPRequest equivalent in Dojo

The traditional way through which we perform AJAX calls to lotusscript agents to obtain responses kept failing for me in XPages. I kept wondering why I was not able to get back any response from the agents.

The following dojo method though different, helped me accomplish the same,

/***************************************************/
      dojo.xhrGet( { // 
        url: "The url of your lotusscript agent", 
        handleAs: "text",
sync: true,
        timeout: 5000, // Time in milliseconds

        // The LOAD function will be called on a successful response.
        load: function(response, ioArgs) { 
         returnValue=response;
         alert(returnValue) ;  // this will alert your print statements from the lotusscript agent
        },

        // The ERROR function will be called in an error case.
        error: function(response, ioArgs) {  
          console.error("HTTP status code: ", ioArgs.xhr.status);
          returnValue= response;
          return returnValue; 
          }
        });
/***************************************************/

How ever I was not able to get the browser wait as I would do when using,
xmlHttp.open(GET,url,false)

The sync flag seems to work differently than I expected in the dojo.xhrGet method

Hope this helps :)

No comments:

Post a Comment