2016-04-15 80 views
0

我控制器funnction代碼點火器的AJAX錯誤

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

我打電話與阿賈克斯 我的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); 
    } 
}); 

}

我沒有得到來自控制器的任何結果功能可按!

+0

你會得到什麼錯誤?什麼是城市的js數據變量?你的網址是否正確?嘗試在AJAX塊中放入'statusCode:{404:function(){alert('Not Found');}},'。 – Elymentree

回答

0

變化在一個AJAX網址

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

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