Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Js/AJAX getting server date not working in IE (php not supported)

    On my server, php is not supported. So I have been trying to implement a util that uses the servers date and time to validate forms and such. I am using javascript but am having trouble with the server-side part.

    I have tried in the following code, but it works only in Opera, Mozilla, Safari
    In IE, i get nothing for 'st' and 'NaN' obviously for date

    Code:
    var xmlHttp;
    function srvTime(){
       
       try {
          //Firefox, opera 8.0+, Safari
          xmlHttp = new XMLHttpRequest();
       }
       catch (err1) {
          //Internet Explorer
          try {
             xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
          }
          catch (err2) {
             try {
                xmlHttp = new ActiveXObject('Microsoft.XMLHTP');
             }
             catch (err3) {
                //AJAX not supported, use CPU time.
                alert("AJAX not supported");
             }
          }
       }
       
       xmlHttp.open('GET',window.location.href.toString(),false);
       xmlHttp.setRequestHeader("Content-Type", "text/html");
       xmlHttp.send('');
       return xmlHttp.getResponseHeader("date");
       
    }
       
    var st = srvTime();
    var date = new Date(st);
    .html file
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    
    <script type="text/javascript" src="date.js">
    </script>
    </head>
    <body>
    <script>document.write(st);</script>
    <p>converted date: </p>
    <script>document.write(date);</script>
    <p>cpudate: </p>
    <script>document.write(Date());</script>
    </body>
    </html>
    If i am unable to do it this way, is there a way to use perl with javascript.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    May I ask why are you using Ajax to display info on the current page? That seems to be a little strange.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New Coder
    Join Date
    Oct 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This information will not be displayed on the page. I am trying to use my server time, not the User's time (Date()) in javascript. These values will be used for expiration testing, and many different uses in forms. (Ex. birthdate drop-down option to be used that has the highest year to be 15 years ago.)

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    So why not create the page using either server side includes or Perl or whatever server side language is supported. Ajax is supposed to be used to update a page after it finishes loading and anything it could do before the page loads can be done without it.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    New Coder
    Join Date
    Oct 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Because I would like to have the time functions stored in an external .js source file that can be used on different pages. So i couldn't figure out how to use SSI. and with perl, or any other server-side program, an alternative would be to have the time generated to a file called datetime and have javascript read the time from the file, but I am not sure how to do that.

    but I did get the http request to work in different platforms....the code is as follows: (Although I am not sure how accurate it is since i have been unable to test it)

    located in .js file
    Code:
    var xmlHttp;
    function srvTime(){
       
       try {
          //Firefox, opera 8.0+, Safari
          xmlHttp = new XMLHttpRequest();
       }
       catch (err1) {
          //Internet Explorer
          try {
             xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
          }
          catch (err2) {
             try {
                xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
             }
             catch (eerr3) {
                //AJAX not supported, use CPU time.
                alert("AJAX not supported");
             }
          }
       }
       
       xmlHttp.open('HEAD',window.location.href.toString(),false);
       xmlHttp.setRequestHeader("Content-Type", "text/html");
       xmlHttp.send('');
       return xmlHttp.getResponseHeader("Date");
    }

  • #6
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    hello my autosuggest is not working on server even is working fine on localhost

    <script type="text/javascript" src="jquery.js"></script>
    <script>
    function suggest(inputString){
    if(inputString.length == 0) {
    $('#suggestions').fadeOut();
    } else {
    $('#country').addClass('load');
    $.post("autosuggest_city.php", {queryString: ""+inputString+""}, function(data){
    if(data.length >0) {
    $('#suggestions').fadeIn();
    $('#suggestionsList').html(data);
    $('#country').removeClass('load');
    }
    });
    }
    }

    function fill(thisValue) {
    $('#country').val(thisValue);
    setTimeout("$('#suggestions').fadeOut();", 10);
    }
    </script>

    <style>
    #result {
    height:20px;
    font-size:16px;
    font-family:Arial, Helvetica, sans-serif;
    color:#333;
    padding:5px;
    margin-bottom:10px;
    background-color:#FFFF99;
    }
    #country{
    padding:3px;
    border:1px #CCC solid;
    font-size:17px;
    }
    .suggestionsBox {
    position: absolute;
    left: 35px;
    top:18px;
    margin: 26px 0px 0px 0px;
    width: 180px;
    padding:0px;
    background-color: #FCA500;
    border-top: 3px solid #000;
    color: #fff;
    }
    .suggestionList {
    margin: 0px;
    padding: 0px;
    }
    .suggestionList ul li {
    list-style:none;
    margin: 0px;
    padding: 6px;
    border-bottom:1px dotted #666;
    cursor: pointer;
    }
    .suggestionList ul li:hover {
    background-color: #FC3;
    color:#FCA500;
    }
    ul {
    font-family:Arial, Helvetica, sans-serif;
    font-size:12px;
    color:#FFF;
    padding:0;
    margin:0;
    }

    .load{
    background-image:url(loader.gif);
    background-position:right;
    background-repeat:no-repeat;
    }

    #suggest {
    position:relative;
    }

    </style>


  •  

    LinkBacks (?)

    1. 03-24-2014, 02:04 AM
    2. 02-28-2014, 07:50 AM

    Posting Permissions

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