Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i access a dynamically changing variable in php page to other html page using jquery ajax method?
    text
    copied!<p>This is php page which echoes variable <code>$correct</code>. Its initial value is <code>0</code>. It is changing with increment in its value but when i load this value after echoing it to other page using jquery ajax method it returns only <code>0</code> not the increment value.</p> <pre><code>&lt;?php $i=1; while($i&lt;=10) { $answer="answer_".$i; ${"answer_$i"}=$_POST[$answer]; $i++; } $correct=0; if($answer_1=="a") $correct=$correct+10; else { if($answer_1=="b" || $answer_1=="c" || $answer_1=="d") $correct=$correct-10; } if($answer_2=="a") $correct=$correct+10; else { if($answer_2=="b" || $answer_2=="c" || $answer_2=="d") $correct=$correct-10; } if($answer_3=="a") $correct=$correct+10; else { if($answer_3=="b" || $answer_3=="c" || $answer_3=="d") $correct=$correct-10; } if($answer_4=="a") $correct=$correct+10; else { if($answer_4=="b" || $answer_4=="c" || $answer_4=="d") $correct=$correct-10; } if($answer_5=="a") $correct=$correct+10; else { if($answer_5=="b" || $answer_5=="c" || $answer_5=="d") $correct=$correct-10; } if($answer_6=="a") $correct=$correct+10; else { if($answer_6=="b" || $answer_6=="c" || $answer_6=="d") $correct=$correct-10; } if($answer_7=="a") $correct=$correct+10; else { if($answer_7=="b" || $answer_7=="c" || $answer_7=="d") $correct=$correct-10; } if($answer_8=="a") $correct=$correct+10; else { if($answer_8=="b" || $answer_8=="c" || $answer_8=="d") $correct=$correct-10; } if($answer_9=="a") $correct=$correct+10; else { if($answer_9=="b" || $answer_9=="c" || $answer_9=="d") $correct=$correct-10; } if($answer_10=="a") $correct=$correct+10; else { if($answer_10=="b" || $answer_10=="c" || $answer_10=="d") $correct=$correct-10; } echo "$correct"; ?&gt; </code></pre> <p>This is script on other page which access this variable <code>$correct</code> but it always result in <code>0</code>,though the variable value is changing on the php page? How can i correct this?</p> <pre><code>&lt;script&gt; $(function(){ $('form').submit(function(event){ event.preventDefault(); $.ajax({ url:"results.php", type:"POST", success:function(result){ console.log(result); $('#results').html("&lt;p&gt;"+result+"&lt;/p&gt;"); } }); }); }); &lt;/script&gt; </code></pre>
 

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