DanielAttard
DanielAttard

Reputation: 3615

Load codeigniter controller and method from javascript

I am using jquery ajax in conjunction with $.confirm and I need to figure out how I can load a codeigniter controller/method in response to the $.confirm. Here is the code:

$.ajax({
    url: sURL + "utility/ajaxFind_In_tblClients",
    type: "POST",
    data: {ClientNum: ClientNum},
    dataType: 'json',
    success: function(json) {   
    $.confirm("The email address registered to this account is:\n\n"      
        +json.ClientEmail+
        "\n\nSend password recovery information to this email address?"+
        "\n\nIf you need assistance, please call 888-526-9999.",
        //YES
        function(){ 

        //need to load a codeigniter controller here        

            $.msg("Password recovery information has been sent.\nPlease check your inbox",
            {header:'Password Sent', live:10000});
            $('#ajaxShield').hide();
        },                      
        //NO 
        function(){
            $.msg("Password recovery information has NOT been sent.",
            {header:'Password Not Sent', live:10000});
            $('#ajaxShield').hide();
        } 
    ) //end of confirm
  }, //end of success: function(json), could be YES or NO inside
    error:function (xhr, ajaxOptions, thrownError){ alert('Problem with utility/ajaxFind_In_tblClients  Status code:'+xhr.status+', Error:'+thrownError);} 
});

Looks like I need help for what to do at line 14. I don't know how to load the codeigniter controller after the user responds "Yes" to the $.confirm. Any ideas? Thanks.

Upvotes: 0

Views: 2303

Answers (2)

Thanh Nguyen
Thanh Nguyen

Reputation: 5352

$.ajax{
    url: "<?php echo base_url()?>controller_name/function_name",
    type: "POST",
    data: "client="+client,
    dataType: "json",
    success: function(){
         //do everything you want for success. it depends on your controller.
    }
}

Upvotes: 0

stormdrain
stormdrain

Reputation: 7895

Create a function:

function send_email(email){
    $.ajax({
        type:'post',
        url: '/email_controller/send_email',
        data: 'email='+email,
        error: function(){},
        success: function(){}
    }
}

and call it in your YES function

Upvotes: 1

Related Questions