Loading ...
Sorry, an error occurred while loading the content.

Re: Retrieving Server Date with YUI Connection (httprequest)

Expand Messages
  • tssha
    ... *** EXAMPLE *** // alias to full Connection Manager namespace var YCM = YAHOO.util.Connect; // create success callback to handle response var callback = {
    Message 1 of 5 , Dec 3, 2007
    • 0 Attachment
      --- In ydn-javascript@yahoogroups.com, "royals87"
      <sportsmaster528@...> wrote:
      >
      > I have developed a working srvdate call that retrieves the server date
      > using a xmlhttprequest. I would like to migrate this to yui connection
      > but am having much difficulty. Below is my code. Is it possible to
      > have this work across all platforms? I wish yui would have better
      > examples explaining this.
      >
      > function srvTime(){
      > var xmlHttp;
      >
      > try {
      > //Firefox, opera 8.0+, Safari
      > xmlHttp = new XMLHttpRequest();
      > //Firefox creates errors with the 'HEAD', so use the 'GET' method
      > instead
      > if (navigator.appName === "Netscape") {
      > xmlHttp.open('GET',window.location.href.toString(),false);
      > xmlHttp.setRequestHeader("Content-Type", "text/html");
      > xmlHttp.setRequestHeader("Range", "bytes=0-30" );
      > xmlHttp.send('');
      > return xmlHttp.getResponseHeader("Date");
      > }
      > }
      > catch (err1) {
      > //Internet Explorer
      > try {
      > xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
      > } catch (err2) {
      > try {
      > xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
      > } finally {
      > //AJAX not supported, returning null therefore using user's
      > time.
      > alert("AJAX not supported, we recommend you use a more
      > recent browser.");
      > return '';
      > }
      > }
      > }
      > xmlHttp.open('HEAD',window.location.href.toString(),false);
      > xmlHttp.setRequestHeader("Content-Type", "text/html");
      > xmlHttp.setRequestHeader("Range", "bytes=0-30" );
      > xmlHttp.send('');
      > return xmlHttp.getResponseHeader("Date");

      *** EXAMPLE ***

      // alias to full Connection Manager namespace
      var YCM = YAHOO.util.Connect;

      // create success callback to handle response
      var callback = {
      success:function(o){
      var dateHeader = o.getResponseHeader['Date'];
      }
      }

      function srvTime(){
      //initalise headers
      YCM.initHeader('Content-Type', 'text/html');
      YCM.initHeader('Range', 'bytes=0-30');
      var trans1 = YCM.asyncRequest(
      'HEAD',
      window.location.href.toString(),
      callback
      }

      Everything you need to get started can be found at:
      http://developer.yahoo.com/yui/connection/

      Regards,
      Thomas
    • royals87
      ... date ... connection ... method ... user s ... The following is what i have in my body section. But for some reason in FireFox, everyother call returns
      Message 2 of 5 , Dec 4, 2007
      • 0 Attachment
        --- In ydn-javascript@yahoogroups.com, "tssha" <tsha@...> wrote:
        >
        > --- In ydn-javascript@yahoogroups.com, "royals87"
        > sportsmaster528@ wrote:
        > >
        > > I have developed a working srvdate call that retrieves the server date
        > > using a xmlhttprequest. I would like to migrate this to yui connection
        > > but am having much difficulty. Below is my code. Is it possible to
        > > have this work across all platforms? I wish yui would have better
        > > examples explaining this.
        > >
        > > function srvTime(){
        > > var xmlHttp;
        > >
        > > try {
        > > //Firefox, opera 8.0+, Safari
        > > xmlHttp = new XMLHttpRequest();
        > > //Firefox creates errors with the 'HEAD', so use the 'GET' method
        > > instead
        > > if (navigator.appName === "Netscape") {
        > > xmlHttp.open('GET',window.location.href.toString(),false);
        > > xmlHttp.setRequestHeader("Content-Type", "text/html");
        > > xmlHttp.setRequestHeader("Range", "bytes=0-30" );
        > > xmlHttp.send('');
        > > return xmlHttp.getResponseHeader("Date");
        > > }
        > > }
        > > catch (err1) {
        > > //Internet Explorer
        > > try {
        > > xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
        > > } catch (err2) {
        > > try {
        > > xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
        > > } finally {
        > > //AJAX not supported, returning null therefore using user's
        > > time.
        > > alert("AJAX not supported, we recommend you use a more
        > > recent browser.");
        > > return '';
        > > }
        > > }
        > > }
        > > xmlHttp.open('HEAD',window.location.href.toString(),false);
        > > xmlHttp.setRequestHeader("Content-Type", "text/html");
        > > xmlHttp.setRequestHeader("Range", "bytes=0-30" );
        > > xmlHttp.send('');
        > > return xmlHttp.getResponseHeader("Date");
        >
        > *** EXAMPLE ***
        >
        > // alias to full Connection Manager namespace
        > var YCM = YAHOO.util.Connect;
        >
        > // create success callback to handle response
        > var callback = {
        > success:function(o){
        > var dateHeader = o.getResponseHeader['Date'];
        > }
        > }
        >
        > function srvTime(){
        > //initalise headers
        > YCM.initHeader('Content-Type', 'text/html');
        > YCM.initHeader('Range', 'bytes=0-30');
        > var trans1 = YCM.asyncRequest(
        > 'HEAD',
        > window.location.href.toString(),
        > callback
        > }
        >
        > Everything you need to get started can be found at:
        > http://developer.yahoo.com/yui/connection/
        >
        > Regards,
        > Thomas
        >

        The following is what i have in my body section.  But for some reason in FireFox, everyother call returns undefined.  I can always have it call it twice or a do-while undefined loop to get around it, but was wondering why this is.

        WHEN i replace HEAD with GET, it seems to be working in all platorms ive tested - firefox, ietab, ie7, ie6, opera

        <body class=" yui-skin-sam">
        <script>
        // alias to full Connection Manager namespace
        var YCM = YAHOO.util.Connect;

        // create success callback to handle response
        var callback = {
           success:function(o){
              document.myForm.time.value=o.getResponseHeader['Date'];
              //var dateHeader = o.getResponseHeader['Date'];
           }
        }

        function srvTime(){
           //initalise headers
           YCM.initHeader('Content-Type', 'text/html');
           YCM.initHeader('Range', 'bytes=0-30');
           var trans1 = YCM.asyncRequest(
              'HEAD',
              window.location.href.toString(),
              callback)
        }

        </script>
        <div>
        <form name="myForm" action="">
        <input type="button" value="Refresh textbox" onclick="srvTime();" />
        <p><br /></p>
        Time:  <input type="text" name="time" size="100" />
        </form>
        </div>
        </body>

      • tssha
        ... wrote: ... HTTP GET is universally supported in those browsers; however, HEAD does not appear to be with the latest FF. HTTP
        Message 3 of 5 , Dec 4, 2007
        • 0 Attachment
          --- In ydn-javascript@yahoogroups.com, "royals87"
          <sportsmaster528@...> wrote:

          <snip>

          > WHEN i replace HEAD with GET, it seems to be working in all platorms ive
          > tested - firefox, ietab, ie7, ie6, opera

          HTTP GET is universally supported in those browsers; however, HEAD
          does not appear to be with the latest FF.

          HTTP HEAD produces some strange results in FF 1.5.0.11/2.0.0.11 where
          the response status nor headers are readable, or return null.
          Implementing a raw XHR object to initate a HEAD request, seems to
          produce the same results.

          If you require the usage of HTTP HEAD, you can create a reasonable
          fascimile with HTTP GET; omit any content response (e.g., HTTP 204).

          Regards,
          Thomas
        • royals87
          ... ive ... as you posted earlier, i have the following code: // create success callback to handle response var callback = { success:function(o){ var
          Message 4 of 5 , Dec 5, 2007
          • 0 Attachment
            --- In ydn-javascript@yahoogroups.com, "tssha" <tsha@...> wrote:
            >
            > --- In ydn-javascript@yahoogroups.com, "royals87"
            > sportsmaster528@ wrote:
            >
            > <snip>
            >
            > > WHEN i replace HEAD with GET, it seems to be working in all platorms ive
            > > tested - firefox, ietab, ie7, ie6, opera
            >
            > HTTP GET is universally supported in those browsers; however, HEAD
            > does not appear to be with the latest FF.
            >
            > HTTP HEAD produces some strange results in FF 1.5.0.11/2.0.0.11 where
            > the response status nor headers are readable, or return null.
            > Implementing a raw XHR object to initate a HEAD request, seems to
            > produce the same results.
            >
            > If you require the usage of HTTP HEAD, you can create a reasonable
            > fascimile with HTTP GET; omit any content response (e.g., HTTP 204).
            >
            > Regards,
            > Thomas
            >

            as you posted earlier, i have the following code:
                     // create success callback to handle response
                     var callback = {
                        success:function(o){
                           var dateHeader = new Date(o.getResponseHeader['Date']);
                        }  
                     }
            function srtvtime() {
                     //initalize headers
                     YCM.initHeader('Content-Type', 'text/html');
                     YCM.initHeader('Range', 'bytes=0-30');
                     var trans1 = YCM.asyncRequest('GET',window.location.href.toString(),callback);
                    
            }

            What I have been able to do is have instead of dateHeader -> document.myform.time.value = teh new Date...
            and have a click button that updates it with an onclick="srvtime()"; 
            That has worked....

            What I am trying to do currently is set the date to a variable on page startup.  For example setting dateHeader onload.
            When I have been trying code, it returns null to me or says dateHeader is not defined, etc.
          Your message has been successfully submitted and would be delivered to recipients shortly.