'Sys is not defined' error when making web request during unload

Last post 05-13-2008 2:39 AM by gprashantraj. 5 replies.

Sort Posts:

  • 'Sys is not defined' error when making web request during unload

    10-03-2007, 12:22 PM
    • Loading...
    • mikee179
    • Joined on 10-03-2006, 2:18 PM
    • Posts 5

    I have an unload handler that makes a web request, and doesn't have a completed handler (it's a request that I want fired off before the next page loads, and I therefore don't care about the response). 

    The request works fine but an Error will show up in FireFox as it loads the next page:

    'Sys is not defined

       _this._webRequest.completed(Sys.EventArgs.Empty);  MicrosoftAjax.debug.js (line 4009)'

     Is this a bug or is there a workaround? 

    Is there another way to specify a web request in which a response is not expected, which makes the executor handling the onreadystatechange event unnecessary?

     Thanks for any insight!

    Mike

     


     

  • Re: 'Sys is not defined' error when making web request during unload

    10-03-2007, 1:48 PM

    Can't you just "stub out" a OnComplete function?

    function OnComplete {
        //Do nothing.
    }
     
    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


    My latest ASP.NET AJAX blog entries.
  • Re: 'Sys is not defined' error when making web request during unload

    10-03-2007, 3:14 PM
    • Loading...
    • mikee179
    • Joined on 10-03-2006, 2:18 PM
    • Posts 5

     This error occurs before the completed handler is even considered, so it doesn't make a difference whether you have a handler or not unfortunately.

    this._onReadyStateChange = function () {

    if (_this._xmlHttpRequest.readyState === 4 ) {

    _this._clearTimer();
    _this._responseAvailable = true;
    _this._webRequest.completed(Sys.EventArgs.Empty); <-- this is where the error occurs in the MicrosoftAjax lirbrary
    if (_this._xmlHttpRequest != null) {
    _this._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
    _this._xmlHttpRequest = null;
    }
    }
    }
     It is the completed method of WebRequest that looks for your completed handler to call.  But it is here that Sys is undefined so we never make it to that method.
     What appears to be happening is that during the transition to the next page, the DOM from the current page is being destroyed to make way for the next page when the web request returns and runs the onreadystatechange event handler, only to find that the microsoftajax library has been unloaded.
    That's the only reason I can think that the Sys namespace would suddenly be unavailable. 
     
    Thanks,
    Mike 

     

  • Re: 'Sys is not defined' error when making web request during unload

    02-02-2008, 1:41 PM
    • Loading...
    • Dimebrain
    • Joined on 07-13-2007, 11:41 PM
    • Posts 68

    I encountered this issue recently and was able to prevent it by simply calling the webRequest's completed event at the end of the request whose response I didn't care about. I was using the AjaxControlToolkit, so I'm not sure if you have ready access to the Sys.Net.WebRequestExecutor, but for what it's worth, adding this line to the end of my request handler function ensured that it wouldn't live to see another page:

    this.get_webRequest().completed(Sys.EventArgs.Empty);

    Some day I'll be able to answer more questions than I ask.
  • Re: 'Sys is not defined' error when making web request during unload

    03-13-2008, 4:34 PM
    • Loading...
    • fbaldoni
    • Joined on 06-06-2007, 5:07 PM
    • Indianapolis, Indiana USA
    • Posts 21

    On page unload call the abort function

        // Get the current executor.
    var executor = wRequest.get_executor();


    // Abort the request.
    executor.abort();

     
    and in your call completed handler make sure to check that a response is available before accessing the web request data

     

    if(!MyExecutor.get_responseAvailable()) return;
     
    this should solve your problem 


     

  • Re: 'Sys is not defined' error when making web request during unload

    05-13-2008, 2:39 AM

    Hi

    I have seen your posting. I have one question where to place this line of code

    "this.get_webRequest().completed(Sys.EventArgs.Empty);"

    where i should paste it after calling webservice or at the end of Success function of webserice which takes return value from webservice.

    regards

    gprashantraj

     

Page 1 of 1 (6 items)