2011-01-22 113 views
-3

嗨,我是codeigniter的新手。 我想改变我的div标签使用jQuery的Ajax。在codeigniter中使用jquery ajax更改div标签的html

+1

您可以加入只是* *一些更多的细节?就像你想添加的东西,你从哪里得到它以及你想要它去的地方?注意,jQuery的介绍(例如http://jqfundamentals.com/book/book.html)在这一点上可能对您有用...... – lonesomeday 2011-01-22 10:12:07

+0

ok lonesomeday我想在我的网站上进行投票。我在codeigniter中制作我的控制器,模型和视图。现在我在我的观点中得到民意调查。当用户对该调查投票时,数据也存储在数据库中。 afterb,我想改变投票状态意味着我想添加该投票。 – enthusiastic 2011-01-22 10:55:30

回答

1

根据您的评论你当前的代码似乎是这样的 -

function submitVote(frmName){ 
    $.ajax({ 
    type: "POST", 
    url: "<?php echo SITEURL; ?>/community/community/add_vote/?", 
    data: "vote="+the_value+"&poll="+poll, 
    success: function(msg){ 
    alert(msg); 
    } 
}); 
} 

我想补充的第一件事情就是从你在哪里得到the_value和poll值enter code here?因为你在代码中没有提到这一点。 其次没有必要在您的网址发送?。另外你在功能中使用的参数frmName无处可用。

你可以修改代码正常工作如下 -

function submitVote(frmName){ 
     $.ajax({ 
     type: "POST", 
     dataType: 'text', 
     url: "<?php echo SITEURL; ?>/community/community/add_vote/", 
     data: "vote="+the_value+"&poll="+poll, 
     success: function(msg){ 
     //i am assuming that from controller in msg you are sending the total number of votes to that particular entity after ending current vote. 
     $('#div id where you have displayed your current vote count').html(msg); 
     } 
    }); 
    }