Jump to content

Reload page before function fires


Hobbyist_PHPer

Recommended Posts

Hi, I have a jQuery function that loads a page inside of a DIV, that page shows an availability status button, only when that status is set to available, the status button becomes a link... here's that link...

    if ($row['AgentLoggedState'] == "available")
    {
        echo '<a href="javascript:void(0);" onclick="showElem(\'RedeemAuthorizationCode\');"><img src="http://xxxxxxxx.xxx/images/status_'.$row['AgentLoggedState'].'.png" alt="'.$row['AgentLoggedState'].'" /></a>';
    }
    else
    {
        echo '<img src="http://xxxxxxxx.xxx/images/status_'.$row['AgentLoggedState'].'.png" alt="'.$row['AgentLoggedState'].'" />';
    }

 

Then on the main page, I have these 2 jQuery functions...

<?
session_start();
include '../../connection.inc';
$query = "SELECT AgentLoggedState FROM Agents WHERE AgentID = '1'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result)
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <link href="http://xxxxxxx.xxx/StyleSheet.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript">
        var showElem;
        showElem = function( showID ) {
        div = (( document.getElementById ) ? document.getElementById( showID ) : document.all[ showID ] );
        try {
        div.className = (( div.className === "hide" ) ? "show" : "hide" );
        } catch( e ) {
        div.style.display = (( div.style.display === "none" ) ? "block" : "none" );
        }
        };
        </script>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script>
        $(document).ready(function() {
                $("#responsecontainer").load("../../response.php");
        var refreshId = setInterval(function() {
            $("#responsecontainer").load('../../response.php');
        }, 1000);
        $.ajaxSetup({ cache: false });
        });
        </script>
    </head>

 

What I need to happen is, when this link, <a href="javascript:void(0);" onclick="showElem(\'RedeemAuthorizationCode\');">, is clicked, I need the main page to first reload, so that it can fire the PHP/MySQL query prior to showing the hidden DIV...

 

Any suggestions would be greatly appreciated... Thank You

Link to comment
Share on other sites

If you reload the page, any running javascript processes are killed. They do not persist between page loads. So you can't really do what you want.

 

If you want something from PHP/MySQL after page load, you will need to use an ajax implementation to do so.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.