Note that there are some explanatory texts on larger screens.

plurals
  1. POrefreshing a <div> with ajax but passing along a counter variable
    primarykey
    data
    text
    <p>I have two <code>.php</code> files. The first one <code>ajax_testing.php</code> looks like this:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;?php $index_local=1; $_SESSION['global_index'] = $index_local; ?&gt; &lt;head&gt; &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="main"&gt;Who is batman? click count=&lt;?echo $_SESSION['global_index'] ?&gt; &lt;button id="detailed"&gt;LINK&lt;/button&gt; &lt;/div&gt; &lt;/body&gt; &lt;script type="text/javascript" language="javascript"&gt; $(document).ready(function() { /// Wait till page is loaded $("button").click(function(){ &lt;?php $_SESSION['global_index']+=1; ?&gt; $('#main').load('property-detailed.php?global_index=' + &lt;?php echo $_SESSION['global_index']; ?&gt; + ' #main', function() {}); }); }); //// End of Wait till page is loaded &lt;/script&gt; &lt;/html&gt; </code></pre> <p>Document number two is called <code>property-detailed.php</code> and looks like this:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;?php $_SESSION['global_index'] = $_GET['global_index']; ?&gt; &lt;head&gt; &lt;script&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="main"&gt;Who is batman? click count=&lt;?php echo $_SESSION['global_index']; ?&gt; &lt;button id="detailed"&gt;LINK&lt;/button&gt; &lt;/div&gt; &lt;/body&gt; &lt;script type="text/javascript" language="javascript"&gt; $(document).ready(function() { /// Wait til page is loaded $("button").click(function(){ &lt;?php $_SESSION['global_index']+=1; ?&gt; $('#main').load('property-detailed.php?global_index=' + &lt;?echo $_SESSION['global_index'] ?&gt; + ' #main', function() {}); }); }); //// End of Wait till page is loaded &lt;/script&gt; &lt;/html&gt; </code></pre> <p>I load the first page, and it has a variable, <code>$global_index</code>, that is set to 1 and a button with an ajax command to reload the <code>div</code> with the new information found on the second page.</p> <p>My goal is to have the variable <code>$global_index</code> carry over and increment each time I press the button. Is this possible with only ajax being implemented? If so, is there a way to make it happen with only the first page? Otherwise would it just be easier to have my database keep track of this number and increment that?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload