title: Complete Javascript Ajax php confusion
body: <p>Hi all I am developing a site in Codeigniter and I have a form that I am posting using PHP and this is absolutely fine. However I have a small dropdown on the side of my page which I am using to jump between pages - in order to do this I am simply using a href and passing variables within the URL. </p>
  
  <p>I need to POST some data however when they click on the link. I don't wish to use a button and was wondering whether this could be acheived using an ajax onclick() event?? - the data I need to post however is within the form. The code structure is roughly:</p>
  
  <pre><code>&lt;form action="main/postback" method="post"&gt;
  &lt;input type="hidden" name="pagereference" value="2" /&gt;
  &lt;input type="hidden" name="supervariable" value="7" /&gt;
  First name: &lt;input type="text" name="firstname"&gt;&lt;br&gt;
  Last name: &lt;input type="text" name="lastname"&gt;
  
  &lt;/form&gt;
  &lt;div&gt;
  &lt;ul&gt;
  &lt;li&gt;&lt;a href = 'http:localhost/landing'&gt;click me&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>When someone clicks on the link I want to send an Ajax Post request, but In the php file that I am posting the data I want to be able to retrieve data from within the form. Is this possible? if so could someone please provide an example AJAX request and how to retrieve the data in PHP as I am majorly confused. I tried the following:</p>
  
  <pre><code>&lt;li&gt;&lt;a onclick='myFunction()'&gt;click me&lt;/a&gt;&lt;/li&gt;
  
  
  &lt;script type="text/javascript"&gt;
                  function myFunction()
                  {
                      var "test";
                       $.ajax({
                             type: "POST",
                             url: "http://localhost/ciproject/assessment/test",
                             dataType: String,
                             success: function(msg){
                                  alert( "Data Saved: " + msg ); //Anything you want
                             }
                           });
                       window.alert("TEST");
                  }
              &lt;/script&gt;   
  </code></pre>
  
  <p>Any ideas would be much appreciated, many thanks </p>