title: Using jQuery JSON in CodeIgniter
body: <p>In CI, I have setup a controller with a method of logsig(). Then in my index() method I'm calling a view called startpage. In my view I'm using JSON to make an asynchronous call between my view and my controller. How would I code the call. Below is the code I have:</p>
  
  <p>Contoller:</p>
  
  <pre><code>function logsig() {
  $this-&gt;load-&gt;view('startpage', $sync);
  header('Content-type:application/json'); .............
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
  $(document).ready(function() {
      // blink script
      $('#notice').blink();
  
      $("#action_button").click(function() {
          var username = $("#username").val();
          var password = $("#password").val();
          var dataString = '&amp;username=' + username + '&amp;password=' + password;
          if(username=='' ||  password=='') {
              $('#success').fadeOut(400).hide();
              $('#error').fadeOut(400).show();
          } else {
              $.ajax({
              type: "POST",
              dataType: "JSON",
              url: "processing/logsig.php",
              data: dataString,
              json: {session_state: true},
              success: function(data){
              if(data.session_state == true) { // true means user is logged in.
                  $("#main1").hide();
                  $('#main1').load('&lt;?=$sync?&gt;').fadeIn();
              } else if(data.session_state == false) { // false means user is being registered.
                  $("#action_button").remove();
                  $('#success').load('&lt;?=$sync?&gt;');
                  // onLoad fadeIn
              }
            }
         });
        }
      });
  });
  &lt;/script&gt;
  </code></pre>