title: Codeigniter how to use jquery within controller
body: <p>I am using codeigniter along with nodejs for real time notifications. Now I simply want the users to notify about the recent changes happened in on of the page(controller).</p>
  
  <p>Hence, I am using socketio along with nodejs to acheieve the notification system. The code goes like this:</p>
  
  <pre><code>var socket = io.connect( 'http://localhost:5000' );
  
  $( "#messageForm" ).submit( function() {
      var nameVal = $( "input[name=nameInput]" ).val();
      var msg = $( "input[name=messageInput]" ).val();
      socket.emit( 'message', { name: nameVal, message: msg } ); //LN1
      alert('posted'); //Sent from client side
      return false;
  });
  
  //Receive the notification as soon as posted(for now, will get the same values posted above)
      socket.on( 'message', function( data ) {
          alert('got response');
          var actualContent = $( "#messages" ).html();
          var newMsgContent = '&lt;li&gt; &lt;strong&gt;' + data.name + '&lt;/strong&gt; : ' + data.message + '&lt;/li&gt;';
          var content = newMsgContent + actualContent;
          $( "#messages" ).html( content );
      });
  </code></pre>
  
  <p>I also however wants to save the changes to the form, so I am posting the form values to a controller, which will save it to the database. After that I want this code to run. </p>
  
  <p>So, I think if I can get it somehow like this, that would be better:</p>
  
  <pre><code>Class Myclass extends CI_Controller
  {
   //....contructors etc.
  
  public function save_form()
  {
     $name = $this-&gt;input-&gt;post('nameInput');
     $msg = $this-&gt;input-&gt;post('messageInput');
     $this-&gt;load-&gt;model('my_model'); //For saving to database
     $saved = $this-&gt;my_model-&gt;save($name, $msg); //returns true is saved
  
     if($saved)
     {
        //Now notify user
        //Please now tell me how to call the socketio javascript from here
     }
     redirect('form_url'); //Redirect back to form, from where is was submitted
  }
  
  //....other functions
  }
  }
  </code></pre>
  
  <p>So can anybody tell me how to call the javascript from within the controller? Is that a good idea? Actually I could have used the way to call the controller from ajax and then using <code>$.ajax.done(function(){ socket.emit( 'message', { name: nameVal, message: msg } ); }</code> but its too late to make the ajax calls all the way threw.</p>
  
  <p>Thanks in advance</p>