CodeIgniter Forums
Jquery post help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Jquery post help (/showthread.php?tid=33294)

Pages: 1 2


Jquery post help - El Forum - 08-22-2010

[eluser]Techno Heart[/eluser]
Ya its empty string.But the same function i have used already in two places.there its working fine ..here am facing this issue...i echo the returned valued in my controller class.but its still returning empty string.you want to look at my model and controller classes ?


Jquery post help - El Forum - 08-22-2010

[eluser]vitoco[/eluser]
post it, there's a demo site that i could check ?


Jquery post help - El Forum - 08-22-2010

[eluser]Techno Heart[/eluser]
My controller function
Code:
function deletePost()
    {
        if($this->session->userdata('candidate_id'))
        {
            if($this->input->post("diss_id"))
            {
                $d_id = $this->input->post('diss_id');
                $post_id = $this->input->post('post_id');
                $parent = $this->input->post('parent');
                $delete = $this->discussionmodel->removePost($d_id,$post_id,$parent);
                echo $delete;
            }
        }
        else
        {
            redirect('/login','location');
        }
    }

My model function
Code:
function removePost($diss_id,$post_id,$parent)
    {
        $moodle = $this->load->database('moodle',true);
        $userid = $this->session->userdata('user_id');
        $first_post = $this->getParent($diss_id);
        $mess = 1;
        if($first_post == $parent)
        {
            $delete_post = "delete from mdl_forum_posts where
             id = $post_id and
             discussion = $diss_id";
            $sql = $moodle->query($delete_post);
            if($sql)
            {
                $data = 1;
            }
            else
            {
                $data = 2;
            }
        }
        else if($first_post == $post_id)
        {
            $query = "delete from mdl_forum_posts where id = $post_id and discussion = $diss_id";
            $sql1 = $moodle->query($query);
            $delete = "delete from mdl_forum_discussions where firstpost = $post_id and id = $diss_id";
            $dele = $moodle->query($delete);
            $delete_diss = "delete from pl_discussion where discussion_id = $diss_id";
            $qry = $moodle->query($delete_diss);
            
            if($query && $dele && $qry)
            {
                $data = 3;
            }
            else
            {
                $data = 2;
            }
        }
        return $data;
    }

Sorry no demo site available. and one more doubt i have is.Is there any limit for using Jquery $.post in a single jquery file ?


Jquery post help - El Forum - 08-23-2010

[eluser]vitoco[/eluser]
i've added son lines
Code:
function deletePost()
    {
        if($this->session->userdata('candidate_id'))
        {
            if($this->input->post("diss_id"))
            {
                $d_id = $this->input->post('diss_id');
                $post_id = $this->input->post('post_id');
                $parent = $this->input->post('parent');
                $delete = $this->discussionmodel->removePost($d_id,$post_id,$parent);
                echo $delete;
            }
            // NO RETURN DEFINED -> -1
            else
            {
                echo '-1' ;
            }
        }
        else
        {
            redirect('/login','location');
        }
    }

My model function
Code:
function removePost($diss_id,$post_id,$parent)
    {
        $moodle = $this->load->database('moodle',true);
        $userid = $this->session->userdata('user_id');
        $first_post = $this->getParent($diss_id);
        $mess = 1;
        if($first_post == $parent)
        {
            $delete_post = "delete from mdl_forum_posts where
             id = $post_id and
             discussion = $diss_id";
            $sql = $moodle->query($delete_post);
            if($sql)
            {
                $data = 1;
            }
            else
            {
                $data = 2;
            }
        }
        else if($first_post == $post_id)
        {
            $query = "delete from mdl_forum_posts where id = $post_id and discussion = $diss_id";
            $sql1 = $moodle->query($query);
            $delete = "delete from mdl_forum_discussions where firstpost = $post_id and id = $diss_id";
            $dele = $moodle->query($delete);
            $delete_diss = "delete from pl_discussion where discussion_id = $diss_id";
            $qry = $moodle->query($delete_diss);
            
            if($query && $dele && $qry)
            {
                $data = 3;
            }
            else
            {
                $data = 2;
            }
        }
        // RETUDN -1
        else
        {
            return -1 ;
        }
        return $data;
    }

see if the $.post it's getting a '-1' string as return

-------------
Sorry no demo site available. and one more doubt i have is.Is there any limit for using Jquery $.post in a single jquery file ?

there's no limit, cause it's a function, you can call it as many times as you want.


Jquery post help - El Forum - 08-23-2010

[eluser]Techno Heart[/eluser]
Ya i added those lines sir. The query executes actually but its returning empty string.same alert i am getting.


Jquery post help - El Forum - 08-23-2010

[eluser]Techno Heart[/eluser]
Is there any chance for the function to deviate to another function in case of usage of same variables in both functions.


Jquery post help - El Forum - 08-24-2010

[eluser]InsiteFX[/eluser]
There is a problem with ajax calls using sessions if you
search the forms you should find the solution, not sure
where it is.

InsiteFX