Note that there are some explanatory texts on larger screens.

plurals
  1. POon click make a server request to change php variable
    text
    copied!<p>I thought I solved the issue in a preceding question but it is sill not working. I want to change the php variables ($start and $end called by var b1 and var b2) if the admin clicks on button. After this the new code should be availble for every visitor, so it should make a server request. Here is my updated code: </p> <pre><code>&lt;?php if(date('w') == 4){ // day 2 = Tuesday $start = strtotime('9:30'); $end = strtotime('12:30'); $timenow = date('U'); if ($timenow &gt;= $start &amp;&amp; $timenow &lt;= $end) { echo'&lt;div id="iar_eu"&gt;'; echo quick_chat(200, 'default', 1, 'left', 0, 0, 1, 1, 1); echo'&lt;/div&gt;'; } } ?&gt; &lt;/div&gt; &lt;?php if ( is_user_logged_in() ) { ?&gt; &lt;input type="submit" value="Start Chat" id="start_chat" style="position: absolute; top: 30px; left: 10px;" /&gt; &lt;?php } ?&gt; &lt;script type="text/javascript"&gt; if(jQuery('#start_chat').data('clicked')) { // change var b1 and b2 $.ajax({ type: "POST", url: "/web/htdocs/www.fattorefamiglia.com/home/wp-content/themes/child_care_creative/chat.php", dataType: 'json', data: { b1: "1:00", b2: "23:00" } }).done(function(data) { b1 = data.b1; b2 = data.b2; });} else { $.ajax({ type: "POST", url: "/web/htdocs/www.fattorefamiglia.com/home/wp-content/themes/child_care_creative/chat.php", dataType: 'json', data: { b1: "9:00", b2: "18:00" } }).done(function(data) { b1 = data.b1; b2 = data.b2; });} jQuery('#start_chat').click(function(){ $(this).data('clicked', true); var b1 = '&lt;?php echo $start; ?&gt;'; var b2 = '&lt;?php echo $end; ?&gt;'; }); &lt;/script&gt; </code></pre> <p>chat.php:</p> <pre><code>&lt;?php // variables if (!empty($_POST)) { $data['b1'] = $_POST['b1']; $data['b2'] = $_POST['b2']; } // to not lose them $_SESSION['chat'] = $data; // to keep it compatible with your old code $start = $data['b1']; $end = $data['b2']; // send the JSON formatted output echo json_encode($data); ?&gt; </code></pre> <p>Nothing happens when I click the button. What am I doing wrong?</p>
 

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