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

[eluser]SSgt Dodger USMC[/eluser]
Hi slowgary!

I tried your suggestion about using the .bind command, but for the life of me I could not get that to work. No matter where I placed the event.preventDefault() the submit function would still execute the form action, and an entire page refresh. Here is the jQuery after my mods:

Code:
$('.updateform').each(function()
    {
        
        var current_form = $(this);
        var id = $(this).attr("id").split("-"); // Split the id value at the hyphen, and grab the ticketnum.
        var ticnum = id[1]; // Set the ticket number from the split value.
        var ajax = true; // Set the ajax variable to true. This is to do ajax checking in the controller.
        current_form.bind('submit', function(event){
            event.preventDefault();  //prevents the form submission

            // Check to see if the textarea is empty.
            if($("#actionlogbox"+ticnum).val() == "")
                { // If empty, return nothing.
                return false; // die!
                }
            else
                { // There is something typed in the textarea, and should be placed into the ticket.
                    $.post("http://localhost/test/index.php/ajaxtasks/actionLog", // This is the URL of the code you want to run when clicked.
                    {
                        updateText: $("#actionlogbox"+ticnum).val(), // Set the variable for the typed in text.
                        ticketNum: ticnum, // set the variable for the ticket number.
                        isajax: ajax // set the method to 'ajax'.
                    },
                    function(data)  // this is what to run if the ajax update is successful.
                        {
                            $('#actionlog-'+ticnum).html(data); // update the screens info on the actionlog.
                            $("#actionlogbox"+ticnum).val(''); // empty the textarea.
                        });
                    return false;  // stop the button from working normally.
                } // End else
            }); // End click function.
     }); // End .each function

Just for clarity sake, my form consists of 4 dropdowns, a textarea (the one we are messing with here) and an update button. When I had the .click function defined earlier, a space-bar-tap on the button would produce the same results as the click. And I was unable to submit with the enter button since it was a text area.

I want this thing to be as best-practices as possible, and I agree that the form submit action is the better-designed option, but this doesn't work for me.

You have been very helpful slowgary, and I thank you again. Any further guidance is greatly appreciated!


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