简体   繁体   中英

Can I send Data to Controller after AJAX Success in PHP Codeigniter?

I want to send "data" to the controller that came from controller to success of ajax and its a different controller function then the first one.

 $.ajax({
    url :'<?= base_url('Content/get_thumb') ?>',  // Controller URL
    type : 'POST',
    data : formData,
    async : false,
    cache : false,
    contentType : false,
    processData : false,
    success : function(data) {   
        $('#video_thumb').show();
        $('#thumb_image').html('<img src="' + data + '" style="margin-top:57px;" /> ');
    }
});

Yes you can, just after success function you can run another function that will send data back to your controller.

$.ajax({
    url :'Controller URL',  // Controller URL
    type : 'POST',
    data : formData,
    async : false,
    cache : false,
    contentType : false,
    processData : false,
    success : function(data) {   
        $('#video_thumb').show();
        $('#thumb_image').html('<img src="' + data + '" style="margin-top:57px;" /> ');
        function_name(data); //run another function to send data.
    }
});  

The function to run on sucess

<script type="text/javascript">
    function function_name(DataToSend) {
        $.ajax({
        url :'<?= base_url('Content/get_thumb') ?>',  // Controller URL
        type : 'POST',
        data : DataToSend,
        success : function(response) {   
            //Do what needs to be done
        }
    });
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM