title: Clear Event ID and call a new one without refreshing the page
body: <p>I'm parsing array of events from mysql and list them into a landing page. The user can click a button to send a message to the event organizer. The user should login before sending the email so I sent the event ID with the http request and return it back when session is sent than call via ajax to populate the modal and send the message. Everything is going fine until now however the user should reload the page to clear the last event id and call a new one all over again.</p>
  <p>Below is the code where I set <code>data-jid=&quot;&lt;?= $jid; ?&gt;&quot;</code> where it set the event id attached to the button and send it via http request once redirected to the login page</p>
  <pre><code>                    &lt;?php if ($this-&gt;session-&gt;userdata('is_user_login')) : ?&gt;
                          &lt;button type=&quot;button&quot; class=&quot;btn btn-secondary btn-block rounded contactBiz&quot; data-toggle=&quot;modal&quot; data-jid=&quot;&lt;?= $jid; ?&gt;&quot;  data-target=&quot;#modalApply&quot;&gt;&lt;?=trans('apply')?&gt;&lt;/button&gt;
                      &lt;?php  else:
                          $last_request_page = (isset($_SERVER['HTTPS']) ? &quot;https&quot; : &quot;http&quot;) . &quot;://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]&quot;;
  
                          $this-&gt;session-&gt;set_userdata('last_request_page', $last_request_page); 
                      ?&gt;
                          &lt;a href=&quot;&lt;?= base_url(); ?&gt;auth/login?id=&lt;?= $jid; ?&gt;&quot; data-jid=&quot;&lt;?= $jid; ?&gt;&quot; class=&quot;btn btn-secondary btn-block rounded preapply&quot;&gt;&lt;?=trans('apply')?&gt;&lt;/a&gt;
                      &lt;?php endif; ?&gt;
  </code></pre>
  <p>In the login page I've set the session of the event id as following:</p>
  <pre><code>&lt;?php
      if(isset($_GET['id'])) {
          $this-&gt;session-&gt;set_userdata('event_id', $_GET['id']);
      }
  ?&gt;
  </code></pre>
  <p>Now after the user redirects back the last clicked button will be populated to send the message using below javascript call.</p>
  <pre><code>&lt;?php if (!empty($this-&gt;session-&gt;userdata('event_id'))) {
      $sID = $this-&gt;session-&gt;userdata('event_id'); ?&gt;
  
      $(document).ready(function(){
          $(&quot;.contactBiz&quot;).trigger(&quot;click&quot;);
      });
  
  &lt;?php } ?&gt;
  &lt;?php if ($this-&gt;session-&gt;userdata('is_user_login')) : ?&gt;
          $('.contactBiz').click(function(e){
              e.preventDefault();
              var id;
              var csrfName = '&lt;?php echo $this-&gt;security-&gt;get_csrf_token_name();?&gt;';
              var csrfHash = '&lt;?php echo $this-&gt;security-&gt;get_csrf_hash();?&gt;';
  
              var data = {
              &lt;?php if (!empty($this-&gt;session-&gt;userdata('event_id'))) { ?&gt;
                  id: &lt;?= $sID; ?&gt;,
              &lt;?php } else { ?&gt;
                  id: $(this).attr('data-jid'),
              &lt;?php } ?&gt;
                  uid: &lt;?= $this-&gt;session-&gt;userdata('user_id'); ?&gt;,
              };
              data[csrfName] = csrfHash;
  
              $.ajax({
                  cache: false,
                  url: base_url + 'job-data',
                  dataType: 'json',
                  type: 'POST',
                  data: data,
                  error: function(jqXHR, textStatus, errorThrown) {
                      alert('Something is wrong');
                  },
                  success: function(data) {
                      console.log(data);
                      $(&quot;#subject&quot;).val(data[0].title);
                      $(&quot;.messageTitle&quot;).empty().append( &quot; &lt;?= trans('message'); ?&gt; &quot; + data[0].name + &quot; about &quot; + data[0].title );
                      p1 = data[0].business_id;
                      p2 = data[0].email;
                      &lt;?php $this-&gt;session-&gt;unset_userdata('event_id'); ?&gt;
                  } 
              }); 
  
          });
  &lt;?php endif; ?&gt;
  </code></pre>
  <p>Now everything as said is fine, the last clicked button is populated using the event id <code>data-jid=&quot;&lt;?= $jid; ?&gt;&quot;</code> but what happens next the user got stuck with the same event id repeated for all buttons.</p>
  <p>The solution I used in the ajax call to define the id as below:</p>
  <pre><code>        &lt;?php if (!empty($this-&gt;session-&gt;userdata('event_id'))) { ?&gt;
              id: &lt;?= $sID; ?&gt;,
          &lt;?php } else { ?&gt;
              id: $(this).attr('data-jid'),
          &lt;?php } ?&gt;
  </code></pre>
  <p>And after the successful ajax response I'm clearing the session as set below:</p>
  <pre><code>            &lt;?php $this-&gt;session-&gt;unset_userdata('event_id'); ?&gt;
  </code></pre>
  <p>I think my mistake is here however I couldn't find any better solution, your advice is highly appreciated thank you!</p>