我试图显示div内ajax响应的值,为此,我在视图文件中包含以下代码。
$(function(){ // added
$('a.vote').click(function(){
var a_href = $(this).attr('href');
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>contents/hello",
data: "id="+a_href,
success: function(server_response){
if(server_response == 'success'){
$("#result").html(server_response);
}
else{
alert('Not OKay');
}
}
}); //$.ajax ends here
return false
});//.click function ends here
}); // function ends here
我的控制器(ajax向其发送值):
function hello() {
$id=$this->input->post('id');
echo $id;
}
现在,我正在尝试实现的是
我尝试了以下代码,但未在div中显示值。
你能告诉我问题出在哪里吗?