代码点火器ajax错误


code igniter ajax error

我的控制器功能

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

我用ajax调用这个函数我的ajax代码是这个

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);
    }
});

}

我没有从控制器功能中得到任何结果!!!

试试这个这对我有用

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)
        },
    });
}
ajax Url 中的更改
url: "<?php echo base_url();  ?>" + "index.php/home/give_form"

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

试试这个

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);
 }
});