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
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Function that runs automatically every second

    Hi there...

    Dont know if this should be in this forum or javascript forum

    Here's the situation...I have a sql table with a column reminder datetime...suppose I set a reminder for today at 3 pm...once its 3 pm, a popup window should appear saying that I have a reminder...

    I am using asp, ajax, sql and javascript...

    Any ideas??

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    It sounds like it should be in the "reinventing the wheel" forum

    But if you're using AJAX then all you need to do is write a JS function that sends an XMLHTTP request for the data, writes it to the page, and then calls itself via a setTimeout().

    In which case this is probably better suited to the JS forum.

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your suggestion Spud...I kinda found a small code that partially does what I was trying...

    Page1.asp

    <body onLoad="something()">

    --------------------------------------------------------------------------
    <script language="JavaScript" type="text/javascript">
    <!--

    function something() {
    var y = window.setInterval("ReminderAlert();", 2000);

    }
    //-->
    </script>
    ------------------------------------------------------------------------
    <script>

    function ReminderAlert()
    {

    //alert("test");
    ajaxpage(Page2.asp?ReturnData=SomethingNEW', 'HIDELATER');
    if (Request.Cookies("Match")="yes")
    {alert("Yes")}
    }
    </script>

    -----------------------------------------------------------------------
    On Page2.asp

    <%if request("ReturnData")="SomethingNEW" then
    mysql="SELECT * FROM Table1"
    Set AllRecords= Con.Execute( mySQL )

    do while AllRecords.eof<>true

    if AllRecords("Field1")<>now() then

    else
    Response.Cookies("Match")="yes"

    end if


    AllRecord.movenext
    loop

    %>
    ----------------------------------------------------------------------

    According to the above code, I get to Page2 but am unable to return anything from Page2 to Page1...Besides the code in red does not work....I want to be able to return some value so I know when the alert should popup...anyclues?

  • #4
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    Instead of using a cookie, can't you just have an ajax page that periodically asks the asp page for things and then get the asp page to Response.Write anything you need back? (then use responsetext or responsexml in the js to get the return data)

    Set the asp page to output xml instead of text/html and the js may be able to parse it easier.

    EDIT: However, if you know all the reminders you have at page load time, can't you just make the js show the reminder at that time... you don't need the js to ask the asp if it is the correct time yet
    Last edited by ghell; 05-05-2007 at 01:27 AM.

  • #5
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks ghell for your feedback...can you give me some small code to explain what you are suggesting...sorry I am an absolute newbie

    Thanks!

  • #6
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    Well its a javascript question and I'm not as good with javascript as I am with ASP, so I would prefer not to give you a bunch of untested code.

    Here is the theory though:

    Javascript can tell the time. You don't need to constantly ask an ASP script if there are any current reminders, you should be able to get a list of reminders with their times and simply display a message at the correct time. This would require no AJAX, though you may wish to get the page refreshing every 10 minutes or so, so that any reminders added after the page was loaded still get set off. (If you get the page refreshing rather than use AJAX, you would only need to load the events that will happen before the next refresh)

    I'm not sure whether there is a way to get something to simply happen at a specific time in javascript. If there is, use that. If there is not, you will need to do something like use setTimeout to create a delay between the current time and the reminder time. When that goes off, get a delay between that time and the time of the next event (assuming there is a next event), and so on.


  •  

    Posting Permissions

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