Welcome Guest, Not a member yet? Register   Sign In
Yet another form validation question ... You know you can help! :)
#4

[eluser]srisa[/eluser]
Code:
if ($this->form_validation->run() == TRUE)
    {
        $this->Songsdb->insertComment($data);
        $ret = array();
        $ret['status'] = 0; // success.
        $ret['message'] = 'Your Comment has been added! :)';
        echo json_encode($ret);
    } else
        
    if ($this->form_validation->run() == FALSE)
    {
        $ret = array();
        $ret['status'] = -1; //error.
        $ret['message'] = validation_errors();
        echo json_encode($ret);  
    }
In your jQuery:
Code:
var params = $("form#form_comment").serialize();
    $.ajax({
            type: "POST",
            url: base_url+"/music/sendcomment",
            data: params,
            dataType: "json",
            success: function(a){
                if (a.status == 0){
                   //success.
                }
                else{
                   //failure.
                }
            }
        });
I had no problems using this approach on firefox but IE was caching the ajax responses. To get around that I sent the no-cache headers from the controller.


Messages In This Thread
Yet another form validation question ... You know you can help! :) - by El Forum - 01-09-2009, 05:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB