Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery Ajax call Codeigniter Controller

In my View page jquery Ajax call like this

onclick: function() {
                        $.ajax({
                            type:'POST',
                            url:"<?PHP echo base_url('trand/report/checking'); ?>",
                            data: {nm:'vnky'},
                            success: function(){
                                  alert("success");
                              },
                              error: function(){
                                alert("error");
                              }
                        });
                        chart2.exportChart({
                            type: 'image/png', 
                            filename: dynmicfilename
                        });

                    }

exportchart function works perfectly .Inside ajax call also working alerts nice, but url is not executed, by using firebug when clicking the url in new tab , then it works fine.

How can I execute url in ajax call. can you help on this ?

like image 757
venky Avatar asked Jan 10 '23 10:01

venky


1 Answers

Here's my code. My controller return json data

$('.edit').click(function() {
    $.ajax({
        url: '<?php echo site_url('your_controller'); ?>',
        type: 'POST',
        data: {
            key: value
        },
        dataType: 'json',
        success: function(data) {
            console.log(data);
        }
    });
});

Inside Ajax call, which alert is shown success or error? I think your JS code is correct. You should check your controller. If you open it in browser and it work fine. You should check csrf_protection config is TRUE or FALSE

like image 138
Minh Quy Avatar answered Jan 19 '23 03:01

Minh Quy