Process Returning Data
Technical Document







When data is coming back into the web page from an operation the returning data must be processes in a common function. The values coming back help allow you to determine what to do. This example shows this in action and how to handle multiple types (return data from 'run', 'dir' and 'getdriveinfo') in the same page. For more sophisticated examples view the HTML source for the demonstration section for file listing, drive enumeration or error handling.

Process Returning Data

<html>
   <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
   <script language="JavaScript" type="text/javascript"> var $jQuery = jQuery.noConflict(); </script>

   <script type="text/javascript">
     jQuery(document).ready(function()
     {
         jQuery("#file_link").on("click", function (event) 
         {      
           event.preventDefault(); // Recommended to stop the link from doing anything else
           document.dispatchEvent(new CustomEvent('funcIntraLaunch',
           {
              'detail': { task: 'run', program: 'notpad.exe', options: 'file_link', showerrors: 'false' } 
           })); 
         });

         jQuery("#list_files_link").on("click", function (event) 
         {      
           event.preventDefault(); // Recommended to stop the link from doing anything else
           document.dispatchEvent(new CustomEvent('funcIntraLaunch',
           {
              'detail': { task: 'dir', program: 'some_table', workingfolder: '%MY_DOCUMENTS%', switches: '*.*' } 
           })); 
         });

         jQuery("#get_drive_info").on("click", function (event) 
         {      
           event.preventDefault(); // Recommended to stop the link from doing anything else
           document.dispatchEvent(new CustomEvent('funcIntraLaunch',
           {
              'detail': { task: 'getdriveinfo', workingfolder: 'C:' } 
           })); 
         });



        // Handle all IntraLaunch responses for all requests
        jQuery.extend
        ({
           funcIntraLaunchLastOpResult: function (responseIntraLaunchLastOpType, 
                                                  responseIntraLaunchDOMElement, 
                                                  responseIntraLaunchDataSet) 
           {
             // Handle a response from running a program from the specific element with HTML ID 'file_link'
             if (responseIntraLaunchLastOpType == "run" && responseIntraLaunchDOMElement == "file_link") 
             { 
               if (responseIntraLaunchDataSet == "0") { alert('Failed to open the program or document.'); } 
               else if (responseIntraLaunchDataSet == "1") { alert('You have opened notepad.'); } 
             }

             // Handle a response from a request to list some files for 'some_table'
             if (responseIntraLaunchLastOpType == "dir" && responseIntraLaunchDOMElement == "some_table")
             {
               var parsedResponse = jQuery.parseJSON(responseIntraLaunchDataSet);
               jQuery.each(parsedResponse, function (sKey, sFileObjectValue)
               {
                 // Show files we got and maybe update #some_table with them
                 alert('File name: ' + sFileObjectValue['file_name']);
               });
             }

             if (responseIntraLaunchLastOpType == "getdriveinfo") 
             { 
                var parsedDriveInfo = jQuery.parseJSON(responseIntraLaunchDataSet);
                jQuery.each(parsedDriveInfo, function (sKey, sDriveDetails) 
                {
                   if (sDriveDetails['ready'] == "0")
                   {
                      // Drive not ready and have nothing
                      alert('Drive ' + sDriveDetails['drive_name'] + ' not ready...');
                   }
                   else
                   {
                      // Drive ready and we should have the details
                      alert('Drive ' + sDriveDetails['drive_name'] + ' (' + sDriveDetails['drive_type'] + ' drive) with volume \'' + sDriveDetails['volume_label'] + '\' found');
                   }
                });
             }
           }
        }); 
     });
   </script>

   <body>
      <a href="#" id="file_link">File open result</a>
      <a href="#" id="list_files_link">Get a list of files</a>
      <a href="#" id="get_drive_info">Get drive data</a>

      <table id="some_table">
      </table>
   </body>
</html>