SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Minneapolis
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Out of Memory upon atob conversion

    I'm working on a basic AJAX implementation and would like some advice from you all. The application I am working on is a resource scheduler, and this particular portion (that which I am posting about) deals with generating a simple calendar/time sheet that reflects resource availability. The process begins as users entering a beginning time into a textbox. When the onblur() event is triggered, the data from the time box is sent to a server-side script via XMLHTTPRequest. The script takes the date, checks time slot availability w/in a database and spits out a calendar (in HTML), which reflects conflicts etc. This is then encoded into base64 and is then passed back to the client-side javascript via a simple xml doc. The javascript reads the XML document, which tells it which method to call and what the parameters are for that method. This is where I'm having problems. The data is getting passed through just fine, but I am getting an "out of memory error" when I try to decode the base64 data that was passed. I confirmed that the data is being passed through, so this seems to be working just fine. Basically, the process comes to a halt when I try to decode the variable. One other interesting spin on this is that when I simply do something like:
    Code:
         //base64 encoded item
         Var stuff =('dw==');
    
         //decode the item
         stuff=atob(stuff);
    
         var head1 = document.getElementById("head1");
              head1.innerHTML = "";
              //push the now decoded item out to the head1 id
              head1.innerHTML = stuff;
    ...I do NOT receive any errors-and it works just fine. But when I try to do this:
    Code:
    function getdaycal(input,response){
          if (response!=''){
           //message = document.getElementById('nameCheckFailed');
        
           var translated = atob(response);
        
          var head1 = document.getElementById("head1");
              head1.innerHTML = "";
              head1.innerHTML = translated;
       
       
            }else{
              // Input mode
              url  = 'http://biomed30.lib.umn.edu/mrcirc/model/modCalDay.inc.php?q=' + input;
               loadXMLDoc(url);
            }
       }
    ///I get this:
    Code:
    Error: [Exception... "Component returned failure code: 0x8007000e (NS_ERROR_OUT_OF_MEMORY) [nsIDOMWindowInternal.atob]"  nsresult: "0x8007000e (NS_ERROR_OUT_OF_MEMORY)"  location: "JS frame :: http://xyzserver/mrcirc/calday.php :: getdaycal :: line 60"  data: no]
    Source File: http://xyzserver/mrcirc/calday.php
    Line: 60
    I'm pretty inexperienced w/javascript. Am I doing something very basic wrong?

    Here is the full script:

    Code:
    //This implementation of Ajax was adapted from http://www.xml.com/pub/a/2005/02/09/...p-request.html
    //JS Forked due to divergent DOM models
    var req;
    function loadXMLDoc(url)
    {
       // branch for native XMLHttpRequest object
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send(null);
        // branch for IE/Windows ActiveX version
        } else if (window.ActiveXObject) {
            req = new ActiveXObject("Microsoft.XMLHTTP");
            if (req) {
                req.onreadystatechange = processReqChange;
                req.open("GET", url, true);
                req.send();
            }
        }
    } 
    
    function processReqChange()
    {
        //alert (reg.readyState);
       // only if req shows "complete"
       if (req.readyState == 4) {
            // only if "OK"
            if (req.status == 200) {
               response  = req.responseXML.documentElement;
               method = response.getElementsByTagName('method')[0].firstChild.data;
               //Decode from Base64
               result = response.getElementsByTagName('result')[0].firstChild.data;
              //alert (method) //checkName('',posthtml)
              eval(method + '(\'\', result )');
           } else {
                alert("There was a problem retrieving the XML data:\n" + req.statusText);
            }
        }
    }    
    
    function getdaycal(input,response){
          if (response!=''){
           //message = document.getElementById('nameCheckFailed');
        
                
        
          var head1 = document.getElementById("head1");
              head1.innerHTML = "";
              head1.innerHTML = response;
       
       
            }else{
              // Input mode
              url  = 'myserver/mrcirc/model/modCalDay.inc.php?q=' + input;
               loadXMLDoc(url);
            }
       }
    Here is the HTML:
    Code:
    <body>
    
    <input id="day" name="day" type="text" onblur="getdaycal(this.value,'')">
    <input id="blah" name="blah" type="text">
    
    <h1 ID="head1">Onblur, this text will be replaced w/the data from
    the xml file</h1>
    </body>

    and finally, here is the xml file

    Code:
    <?php
    header('Content-Type: text/xml');
    ?>
    <?php echo '<?xml version="1.0" encoding="UTF-8"
      standalone="yes"?>'; ?>
    <response>
      <method>getdaycal</method>
      <result>
    dw==
      </result>
    </response>


    My original plan was to write this exclusively for Mozilla & Netscape, so no worries on the use of atob. I had also planned on boosting the cache in order to allow for the output of a fair amount of html via the base64 method. Is this feasable, or are there problems that I'll run into w/this method?

    I'll thank you very much in advance of a response. Thanks!!!

  2. #2
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe the problem here is simply the newline characters in your <result> element. It's actually a bug in Mozilla that it reports the wrong kind of error if it encounters invalid characters in atob()'s argument.

  3. #3
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Minneapolis
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Yes!!

    OMG, that was it. I should have known, that makes sense since there is no trim functionality going on here. Thank you very, very much!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •