Welcome Guest, Not a member yet? Register   Sign In
ci + jquery
#11

[eluser]ardinotow[/eluser]
Thanks mate...Now I can use codeigniter validation to validate form in ajax way.

I have more question.
Supposed I have one page that contain comment form and comment list. If I post new comment I want to get these instance:
1. The form is validate using ajax, and when no errors occur my new post will be inserted in database then showing 'input success' message (all in ajax way).
2. While showing 'input success' message, the comment list will refreshed in ajax.

I know how to do the first instance, but I don't know how to do the second instance. Please anyone help me to get this work.

p.s. Here is my jquery script for doing the first instance
Code:
// GLOBAL PARAMS
var file            =    'http://localhost/advoria-ci-FA/comment/do_input_ajax';
var placeholder        =    '#wrapper';
var waitholder        =    '#err';
var waitnote        =    '<img alt="" src="http://localhost/advoria-ci-FA/advoria-assets/gambar/wait.gif" />Please Wait ...';
            
// DOM READY
$(document).ready(function()
{
      
    // AJAX SUBMIT OPTIONS /
    var options = {
        beforeSubmit:    wait,
        success:        ShowResult,
        url:            file,
        type:              'post',
        dataType:          'json',
        clearForm:         false,
        resetForm:         false,
        timeout:           3000
    };
    // ON SUBMIT FORM
    $('#ajaxcomment').submit(
        function(){$(this).ajaxSubmit(options);return false;});
    //*/
});
            
// SHOW RESULT
function ShowResult(data)
{
    if(data.success == 'false')
    {
        $('#id_user_error').html(data.id_user_error).slideDown('slow');
        $('#isi_komentar_error').html(data.isi_komentar_error).slideDown('slow');
        $('#rating_error').html(data.rating_error).slideDown('slow');
    }
    if(data.success == 'true')
    {
        $('#id_user_error').fadeOut('slow').hide();
        $('#isi_komentar_error').fadeOut('slow').hide();
        $('#rating_error').fadeOut('slow').hide();
        $(placeholder).html(data.title).slideDown('slow');
    }
    $(waitholder).fadeOut('slow').hide();
}        

            
// WAIT MESSAGE
function wait()
{
    $(waitholder).html(waitnote).fadeIn('fast');
}
            
// CLEAR WAIT MESSAGE
function wipe()
{
    $(waitholder).fadeOut('fast').html('');
}
#12

[eluser]onejaguar[/eluser]
Assuming you are using CSS layout for your comments, something like:

Code:
<div id="comment_container">
  <div class="comment">This is Comment 1</div>
  <div class="comment">This is Comment 2</div>
</div>

you could have your "do_input_ajax" routine return another variable containing the processed text of the new comment, so when data.success == 'true' it will also pass data.comment_html. In "ShowResult()" add this line to the "true" block:

Code:
$('#comment_container').append('<div class="comment">'+data.comment_html+'</div>');

You could also do a second ajax request to get the comment data but less requests is better!
#13

[eluser]ardinotow[/eluser]
@onejaguar
Awesome, thanks dude.

I Love CI+jquery ;-P
#14

[eluser]aster1sk[/eluser]
I did a little video tutorial on this - hope it helps.

How To : CodeIgniter, jQuery & JSON
#15

[eluser]boltoncole[/eluser]
Hey Summer Student!
Really thanks for your video!

Your site is really great ^^
#16

[eluser]aster1sk[/eluser]
[quote author="boltoncole" date="1261099174"]Hey Summer Student!
Really thanks for your video!

Your site is really great ^^[/quote]

boltoncole - thank you very much, expect more goodies in the near future now that I have teamed up with CodyPChristian Wink
#17

[eluser]excelln[/eluser]
[quote author="Gavin Blair" date="1211712454"]@ardinotow: I have the entire thing here: http://zoeandgavin.com/wpmu/php/2008/05/...e-igniter/ (there is a download link at the end) If you want to put more than one input, use the syntax: {id: id.value, username: username.value} - just separate with commas. The controller just gets the stuff from the database and echoes out the result. You can use another view and have the controller pull it in, just know that the entire view will go into your div.[/quote]

Gavin Blair, could you please take a look at the zip file on your website? I downloaded the zip file; when I am trying to unzip it, I got an err msg saying that the zip file is either in unknown format or damaged. Thank you!
#18

[eluser]daK[/eluser]
[quote author="excelln" date="1276591614"][quote author="Gavin Blair" date="1211712454"]@ardinotow: I have the entire thing here: http://zoeandgavin.com/wpmu/php/2008/05/...e-igniter/ (there is a download link at the end) If you want to put more than one input, use the syntax: {id: id.value, username: username.value} - just separate with commas. The controller just gets the stuff from the database and echoes out the result. You can use another view and have the controller pull it in, just know that the entire view will go into your div.[/quote]

Gavin Blair, could you please take a look at the zip file on your website? I downloaded the zip file; when I am trying to unzip it, I got an err msg saying that the zip file is either in unknown format or damaged. Thank you![/quote]

+1
I'm very interesting in seeing how you make it work too. Unfortunately the link is dead...

Could you (or a fellow member) kindly re-upload it and share it with some of us inexperienced CI-late-commers?

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB