如何将一些ajax数据发布到控制器功能并将其恢复?因为我想在函数中发布一个整数,并获得另一个整数(对于发布ID的项目的总投票数),并且在成功时我希望回显该投票计数.
我不知道如何将“id”发布到控制器功能.请看我的代码:
我不知道如何将“id”发布到控制器功能.请看我的代码:
//post this integet
the_id = $(this).attr('id');
$.ajax({
type: "POST",data: the_id,url: "http://localhost/test/index.PHP/data/count_Votes",success: function(){
//the controller function count_Votes returns an integer.
//echo that with the fade in here.
}
});
$.ajax({
type: "POST",data: {data:the_id},success: function(data){
//data will contain the Vote count echoed by the controller i.e.
"yourVoteCount"
//then append the result where ever you want like
$("span#Votes_number").html(data); //data will be containing the Vote count which you have echoed from the controller
}
});
在控制器中
$data = $_POST['data']; //$data will contain the_id //do some processing echo "yourVoteCount";
澄清
我觉得你很困惑
{data:the_id}
同
success:function(data){
为了您自己的清晰度,两个数据都是不同的,您可以将其修改为
success:function(Vote_count){
$(span#someId).html(Vote_count);