SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2011
    0 Post(s)
    0 Thread(s)

    Smile Can you execute a function on trigger from a php file / ajax ?


    I have a website which has a mysql db which records how many visitors i have.
    I want a message box to pop up everytime a visitor logs on.

    Whenever someone logs on, a php file constantly is run (via javascript) checks to see if the visitor counter has increased.
    if it does it plays a "ping" sound. this works fine, but I think as the php file is seperate from my index.php
    the message never appears.

    is there a way to check in javascript that when a responsetext (ajax) changes from the current value being polled that it executes a function? (ie, the notify box)

    many thanks.... twisting my melon.... kev

  2. #2
    Join Date
    Apr 2011
    no fixed address
    0 Post(s)
    0 Thread(s)
    You can store the responseText in a global variable. When the next ajax request is sent to check if any more visitors have logged in, compare its responsetext value with the global variable value and if the visitor count has increased display an appropriate message. This can all be done in your onreadystatechange handler.


Posting Permissions

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