Welcome Guest, Not a member yet? Register   Sign In
Ajax issue
#1

[eluser]detooth[/eluser]
Hey everyone,

Im new to CI but have much experience with PHP and many other langs. I have developed AJAX methods for a while now but am running into a strange issue with CI.

I am using jQuery to make the post to a delete method in an account controller. I can make hte post without a problem, the delete happens and I get a return. The problem is that I want to only return the success or failure STRING. However, I am being returned the entire HTML of my application layout.

Is there any way to make the output a simple string?

This is my delete method:

Code:
function delete($id)
    {
        $data = $this->Account_model->get($id);

        if ($this->Account_model->delete($id))
        {
            if(isAjaxRequest())
            {
                $message = "$data->FirstName has been deleted";
                return $this->output->set_output($message);
            }
            else
            {
                $this->session->set_flashdata('message', "$data->FirstName has been deleted.");
                redirect('account/index');
            }
                                    
        }
        else
        {
            if(isAjaxRequest())
            {
                $message = "Database error";
                return $this->output->set_output($message);
            }
            else
            {
                $this->session->set_flashdata('message', "No data found.");
                redirect('account/index');
            }
        }
        
    }
#2

[eluser]detooth[/eluser]
Actually, I think I may know what the problem is. I will post later when if I have it.
#3

[eluser]detooth[/eluser]
OK. I followed this thread to create a RoR type layout system:

http://ellislab.com/forums/viewthread/57902/

Using the code posted (which works great by the way), I kept returning the view in my layouts folder as the result. So, I added a check in the Yield.php file to determine if the request is an AJAX request. If so, I return the output at this point.

Works great. If anybody else runs into this, I would be happy to post my solution.




Theme © iAndrew 2016 - Forum software by © MyBB