code igniter ajax error

时间:2016-04-15 14:55:12

标签: php codeigniter

my controller funnction

    public function give_form()
{
    if($this->session->userdata('use'))
    echo "user";
    else
    echo "sassa";
}

i am calling this function with ajax my ajax code is this

function discount(){
alert('hi');
jQuery.ajax({
    url: "<?php echo base_url();  ?>" + "index.php/home/give_form",
    type: "post",
    data: "cityy="+city,
    success: function(response) {
    alert(response);
    }
});

}

i am not getting any result from controller funciton!!!

3 个答案:

答案 0 :(得分:2)

  

试试这个   这对我有用

function discount(){
alert('hi');
 $.ajax({
        url: "<?php echo base_url();  ?>/index.php/home/give_form",
        dataType: 'json',
        type: "POST",
        data: {cityy: city},
        success: function(response) {
            alert(response)
        },
    });
}

答案 1 :(得分:0)

更改您的ajax网址

url: "<?php echo base_url();  ?>" + "index.php/home/give_form"

 url: <?php echo base_url();  ?> + "index.php/home/give_form"

答案 2 :(得分:0)

试试这个

function discount(){
alert('hi');
var base_url = window.location.origin;
jQuery.ajax({
   url: base_url + "/index.php/home/give_form",
   type: "post",
   data: "cityy="+city,
   success: function(response) {
   alert(response);
 }
});