[eluser]rickrude[/eluser]
Hi there.
I have just in the last couple of weeks started using codeigniter, and better yet, yesterday I started learning about jquery. I am a complete noob so here goes.
I am having trouble with using jquery $.post to retrieve data via a controller function. I am trying to follow the MVC standards.
Code:
$("a").click(function(show)
{
var stuff = $(this).text();
show.preventDefault();
$.post('users/getusertest', { user: stuff },
function(output){
$('#usage').html(output);
});
});
This works, but it consumes 100% server CPU for at least 5 seconds per click. I have narrowed it down to this -
Code:
$.post('users/getusertest', { user: stuff }
if I create a test.php file for processing the $.post, I don't get cpu problem!
Code:
$.post('test.php', { user: stuff }
TEST.PHP
Code:
<?php
echo "user test ".$_POST['user'];
?>
I am trying to keep the code as clean as possible.
Here is the controller with the getusage function:
Code:
<?php
class Users extends CI_Controller
{
function __construct() {
parent::__construct();
$this->load->model('getdata_model');
}
function index()
{
$this->view();
}
function view()
{
... lots of calls to the model
}
function getusertest()
{
echo "RETURNED ".$_POST['user'];
}
}
?>
The reason I am using jquery to do the post stuff is because I am trying to avoid page refreshes. I am open to criticism, not even sure if this is the best way.
cheers.