Welcome Guest, Not a member yet? Register   Sign In
Updating my news post (with jquery/Ajax)
#21

[eluser]pickupman[/eluser]
Here's a working sample of your code. Unzip and place in your CI application folder. I added a small sql file for the table layout I used for testing. You can use the url /newstest/edit/(some news id).
I renamed the model stuff as to not to overwrite any of your stuff, but you should still be able to follow the code.
#22

[eluser]DynamiteN[/eluser]
[quote author="pickupman" date="1271099039"]Here's a working sample of your code. Unzip and place in your CI application folder. I added a small sql file for the table layout I used for testing. You can use the url /newstest/edit/(some news id).
I renamed the model stuff as to not to overwrite any of your stuff, but you should still be able to follow the code.[/quote]

oh , thank you, will check iy out right away , let u know if its working Smile

EDIT:
I tried to implement your code to mine, but i just get errors on errors, i dont know, maybe i need a break for a day from this, i will try again tomorrow with a bit fresher eyes..
#23

[eluser]pickupman[/eluser]
You may need to adjust the name of the table in the example I attached to match yours. Take a look in the models folder, and edit the name of the table where it gets/updates the record.
#24

[eluser]DynamiteN[/eluser]
Okey now i am getting somewhere...
i just altered for the models to pick up 'news_id' instead of id so i didnt get errors there

i went going on tihis jquery,
Code:
jQuery(document).ready(function($){
    $("#message").hide();
            // $.AJAX Example Request
    $('#news_form').submit(function(eve){
        eve.preventDefault();
        
            $.ajax({
                type: "POST",
                data: $(this).serialize(),
                dateType: 'html',
                url: "<?php echo site_url('admin/admin_news/UpdateNews/'.$newspost->news_id);?>",
                success: function(response, status, request){
                    $("#message").append(response).addClass("ui-corner-all ui-state-highlight").fadeIn("slow");
                },
                error: function(){
                    $("#message").html("Update Error!").addClass("ui-corner-all ui-state-error").fadeIn("slow");
                }
                
            });
        

    });

});

And now it does work.. sort of..
if i post the data now with the fields all filled in correct it then shows up "news updated"
and if i would leave lets say author field empty, it then show that validation error above the form, jsut as i want it to ...
--
NOW the problem Smile
if i would to lets say press two times when the author field i empty it shows the validation error, BUT it show it two times,
same goes if i would to actually update the news correct, and then maybe see a typo in the news or something, and fix it and press update again it then goes ahead adnd update it again, but it then repeats the line "news Updated" next to the first "News Updated" line

other wise it does work.

any idea how to fix that repeat issue, also i would like to have something like that busy function to show when i press before any success or fail message comes up , just so that it shows it's doing something , if u know what i mean Smile

thanks alot for this help, would still have been stuck if you wouldnt have helped me Smile
#25

[eluser]pickupman[/eluser]
Looks like you may have removed part of the code I had that took care of the dupes. It's the line under the submit handler.
Code:
jQuery(document).ready(function($){
    $("#message").hide();
    $('#busy').hide();
            // $.AJAX Example Request
    $('#news_form').submit(function(eve){
        $('#busy').show('slow');
        $("#message").fadeOut('fast').empty(); //remove message after clicking submit
      
            $.ajax({
                type: "POST",
                data: $(this).serialize(),
                dateType: 'html',
                url: "<?php echo site_url('admin/admin_news/UpdateNews/'.$newspost->news_id);?>",
                success: function(response, status, request){
                    $("#message").append(response).addClass("ui-corner-all ui-state-highlight").fadeIn("slow");
                    $('#busy').hide('slow');
                },
                error: function(){
                    $("#message").html("Update Error!").addClass("ui-corner-all ui-state-error").fadeIn("slow");
                    $('#busy').hide('slow');
                }
                
            });
        eve.preventDefault();

    });

});
EDIT: Added to hide/show your busy div.
#26

[eluser]DynamiteN[/eluser]
oh, fixed that now, now it works :O YAY

Think i will leave all this now like that until i will need some more of my web app Smile

THANK YOU, u have helped out BIG time <3

hopefully, i can help back sometime , when my knowledgebase is a little bitgger Wink




Theme © iAndrew 2016 - Forum software by © MyBB