• I know the basics of jQuery and Ajax and am now wanting to make a data import utility in my child theme admin page.

    Expanding on the information here http://codex.wordpress.org/AJAX_in_Plugins , (which I pretty much know how to use), I would like to display a dynamic log/activity file on the admin page as things happen in my data import php functions. I expect I should be able to use something like jQuery(‘#response-area’).append(newestTextline) to show my results.

    Can anyone here tell me how I can send line-by-line of text back to the client side as they happen and not all at once when the import finishes? I also know how to update an external log text file but if it is easy to just show the dynamic log on my admin page, that is preferable. Any ideas or examples?

    Thanks, Ron

Viewing 1 replies (of 1 total)
  • Thread Starter Ron Strilaeff

    (@ronstrilaeff)

    Ok, my solution to this required some rethinking.

    The javascript/jquery/ajax/client side pulls the status periodically from the php/server side. This is under control of a pair of javascript timer statements:

    intervalID = setInterval(getstatus, 2000);
    clearInterval(intervalID);

    The purpose of the getstatus js function is a separate ajax call to read the pct complete (or whatever you want) from the server. The server does not push data back to the client … it responds to a request for a status update.

    On the server side, the (time consuming) main process periodically does a quick and easy update_option(option_name, option_value) to put the pct complete value into the database whenever the %$#& it wants (without interrupting or slowing down any tight loops).

    Then, the php handler of the getstatus ajax call simply does a get_option of the same option_name and responds to the client with the value that was saved asynchronously by the main process. Almost elegant! 🙂

    I had a minor glitch where the get_option returned null occasionally, but since it is not critical, I’m moving on.

    I also tried to make global php vars work for this but I guess they are not static between function calls … php session vars might work but that seemed too complicated.

    Anyways, maybe someone will stumble upon this thread and it will help them. Good luck and have fun!

Viewing 1 replies (of 1 total)
  • The topic ‘How do I dynamically update an admin page using ajax’ is closed to new replies.