Welcome Guest, Not a member yet? Register   Sign In
Trying to get jQuery/Ajax to work with CI
#1

[eluser]SSgt Dodger USMC[/eluser]
I have a problem trying to get CodeIgniter and jQuery to produce ajax functionality. I have been coding all day, learning jQuery, and generally getting my butt kicked. Let me break down the situation, and hopefully someone will have the courage to help me.

I have a trouble ticket system that displays many tickets on a page... each ticket is nested inside of a multitude of divs like so:
Code:
<div class="eachticketwrapper" id="ticket-362">
   <div class="actionlog">
        &lt;form action="&lt;?= base_url();?&gt;admin/updateticket/362" method="post" id="362" name="362"&gt;
           <ul class="displayinline">
           <p>Action Log:
           <span class="actionlog-362">
                &lt;?php echo $actionlog; ?&gt;
            </span>
            </p>
   </div> &lt;!--actionlog--&gt;
            <p>
        &lt;textarea name="actionlogbox362" cols="100" rows="2" id="actionlogbox362" style="" &gt;&lt;/textarea>
        </p>
            <div class="finalbuttons">
                &lt;?php echo form_open('admin/updateticket/'.'362'); ?&gt;
            <li>&lt;?php
                            $attrib = "class='updatebutton-362' id='updatebutton-362'";
                            echo form_submit("RapidTask",'Update',$attrib); //setup the button, and set permissions. ?&gt;</li>
                &lt;?php echo form_close(); // close the form. ?&gt;
             </div> &lt;!--finalbuttons--&gt;
</div> &lt;!--eachticketwrapper--&gt;

When run, the $actionlog should resemble something like the following:

Code:
worker - 2009-06-25 18:15:23 - Received and Acknowledges Ticket.
worker - 2009-06-25 18:15:23 - Changed Status to In Progress
worker - 2009-06-25 18:15:46 - Changed Priority to High
worker - 2009-06-25 18:15:46 - Changed Category to Network Connection Problem
worker - 2009-06-25 18:17:16 - did something

And then there is a textarea and an update button following it.

Here is the contents of my supplementary jQuery file:

Code:
$(document).ready(function() {
    $('.updatebutton-362').click(function()
        {
            var id = $(this).attr("id").split("-"); // Split the id value at the hyphen, and grab the ticketnum.
            $('.actionlog-'+id[1]).load('http://localhost/ci/index.php/ajaxtestc/');  // do something...
            return false; // return false so default click behavior is not followed.
        });
});

the ajaxtestc controller looks like this:

Code:
function index()
    {
        $data['actionlog'] = $this->m_tickets->actionLogPull(362);
        $this->load->vars($data);
        $this->load->view('content/ajaxtestform');
    }
And the m_tickets model looks like this:

Code:
function actionLogPull($requestedNum=NULL)
    {
        $this->db->where('ticketnum', $requestedNum); // Grab only the status for the ticket requested $requestednum=NULL
        $requestedTicket = $this->db->get('tickets'); // set the initial ticket info to a variable
        $returnvalue = $requestedTicket->row('actionlog');
        return $returnvalue;
    }


Now... here is what I WANT. I want to click the update button, have it take what ever the worker has typed into the textarea, add it to the end of the existing log in the database, and refresh the actionlog on the screen.

I can't come up with a clear way to do this. Can anyone shed some light on how I could start this process?

Any help is greatly appreciated, and thanks in advance.


Messages In This Thread
Trying to get jQuery/Ajax to work with CI - by El Forum - 06-27-2009, 01:45 AM
Trying to get jQuery/Ajax to work with CI - by El Forum - 06-27-2009, 12:05 PM
Trying to get jQuery/Ajax to work with CI - by El Forum - 06-27-2009, 09:06 PM
Trying to get jQuery/Ajax to work with CI - by El Forum - 06-27-2009, 10:24 PM
Trying to get jQuery/Ajax to work with CI - by El Forum - 06-27-2009, 10:30 PM
Trying to get jQuery/Ajax to work with CI - by El Forum - 06-28-2009, 02:29 AM
Trying to get jQuery/Ajax to work with CI - by El Forum - 06-28-2009, 10:24 AM
Trying to get jQuery/Ajax to work with CI - by El Forum - 06-28-2009, 09:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB