title: Ajax request in Codeigniter
body: <p>I have been trying to create an ajax request in codeigniter. I've seen this question: <a href="https://stackoverflow.com/questions/16378887/simple-ajax-codeigniter-request">Simple Ajax/Codeigniter request</a> but I wasn't able to absorb that as there were the answers in which people were using <strong>PHP inside Javascript</strong>. I didn't know it was possible, however I gave that a try but it seems like the PHP wasn't being executed. </p>
  
  <p>So here are my questions:</p>
  
  <ol>
  <li><strong>Is it really possible to use PHP inside Javascript,</strong> or am I mistaken?</li>
  <li>What's the <strong>right way to perform an Ajax request in Codeigniter</strong>? What I've tried is the following:</li>
  </ol>
  
  <p><code>var param = {name : event_name, date : event_date, time : event_time};</code></p>
  
  <pre><code>            $.ajax({
                  // As seen from the question here at stackoverflow.
                  url : "&lt;?php echo base_url('event/new_event'); ?&gt;",
                  type : 'POST',
                  data : param,
                  beforeSend : function(){ },
                  success : function(){
                      alert("Event created! Feel free to add as much details as you want.");
                      namebox.val("");
                      $("#new-event-modal").find(".close").trigger('click');
                      window.location.href = "&lt;php echo base_url('user/dashboard'); ?&gt;";
                  },
                  complete : function(){ },
                  error : function(){ }
              });
  </code></pre>
  
  <p>I know the possibility that I could hardcode the <code>URL</code> in the request but that wouldn't be a good practice!!</p>