Note that there are some explanatory texts on larger screens.

plurals
  1. POPhp Sessions and Ajax
    primarykey
    data
    text
    <p>Within my index.php file I have an AJAX function that will call a function within another php file which should increment a number and return it whenever i call the AJAX function.</p> <p>The problem is that the number never changes. I have tried lots of different things. Too many to list them all unfortunately.</p> <p>My index.php file.</p> <pre><code>&lt;?php session_start(); $_SESSION['views'] = 0; ?&gt; &lt;?php include 'blogFunction.php';?&gt; &lt;script type="text/javascript"&gt; function doSomething() { $.ajax({ url: '/blogFunction.php', data: {action: 'test'}, type: 'post', success: function(output) { document.getElementById("blog").innerHTML = ''; document.getElementById("blog").innerHTML = output; } }); } &lt;/script&gt; &lt;div class ="blog" id = "blog"&gt;&lt;/div&gt; </code></pre> <p>my blogFunction.php</p> <pre><code>&lt;?php if(isset($_POST['action']) &amp;&amp; !empty($_POST['action'])) { $action = $_POST['action']; switch($action) { case 'test' : blogreturn();break; } } function blogreturn(){ $_SESSION['views'] = $_SESSION['views']+ 1; echo "THIS number is:" .$_SESSION['views']; } ?&gt; </code></pre> <p>Right now the output is always '1' whenever i hit the button that calls the AJAX function.</p> <p>Any help appreciated.</p> <p>Live Code:<a href="http://retrovate.co.uk" rel="nofollow">here</a></p> <p>Thank you all for the help so far. One problem down, a new problem appears. </p> <p>Extended Functionality:</p> <pre><code>session_start(); if(isset($_POST['action']) &amp;&amp; !empty($_POST['action'])) { $action = $_POST['action']; switch($action) { case 'test' : blogreturn();break; } </code></pre> <p>}</p> <pre><code>function blogreturn(){ $request_url = "http://retrovate.tumblr.com/api/read?type=posts"; $xml = simplexml_load_file($request_url); $a = $_SESSION['views']; $b = $_SESSION['views'] +4; echo "A = ".$a; echo "B = ".$b; $_SESSION['views'] = $_SESSION['views']+ 1; for ($i = $a; $i &lt;= $b; $i=$i+1) { echo '&lt;h2&gt;'.$xml-&gt;posts-&gt;post[$i]-&gt;{'regular-title'}.'&lt;/h2&gt;'; echo '&lt;br&gt;'; echo $xml-&gt;posts-&gt;post[$i]-&gt;{'regular-body'}; echo '&lt;br&gt;'; echo '&lt;br&gt;'; } } </code></pre> <p>The problem that lies here, is, I click my button once at <a href="http://retrovate.co.uk" rel="nofollow">my site</a></p> <p>and it increments and shows the new content. I click again and it reverts back to 0. If I click the button numerous times fast, it seems to work. It seems that chrome is having this problem whereas Firefox is not.</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.
    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