上面是HTML$('#follow').click(function(){if($(".follow").text() == "关注"){ var form_data = {">
时间:2021-07-01 10:21:17 帮助过:3人阅读
0){echo 'message';}?>" >上面是HTML
$('#follow').click(function(){
if($(".follow").text() == "关注")
{
var form_data = {
pid:,
ajax:'1'
};
$.ajax({
url:"",
type:'POST',
data:form_data,
success:function(msg){
$('#follow').html();
}
});
}
else
{
var form_data = {
pid:,
ajax:'1'
};
$.ajax({
url:"",
type:'POST',
data:form_data,
success:function(msg){
$('#follow').html(msg);
}
});
}
return false;
})上面是我写的jquery代码,功能实现了,但是为什么只有等手动刷新本页面才能看到结果呢?
下面的 CI控制器的写法,求指导。。
function addfollow(){
$pid = $this->input->post('pid');
if($this->input->post('ajax')){
}
}
0){echo 'message';}?>" >上面是HTML
$('#follow').click(function(){
if($(".follow").text() == "关注")
{
var form_data = {
pid:,
ajax:'1'
};
$.ajax({
url:"",
type:'POST',
data:form_data,
success:function(msg){
$('#follow').html();
}
});
}
else
{
var form_data = {
pid:,
ajax:'1'
};
$.ajax({
url:"",
type:'POST',
data:form_data,
success:function(msg){
$('#follow').html(msg);
}
});
}
return false;
})上面是我写的jquery代码,功能实现了,但是为什么只有等手动刷新本页面才能看到结果呢?
下面的 CI控制器的写法,求指导。。
function addfollow(){
$pid = $this->input->post('pid');
if($this->input->post('ajax')){
}
}
好吧,问题我自己解决了 要感谢@joyqi 的提示
主要是是操作数据的时候没有返回值, $ajax重写一定要这样写
success:function(msg){
$('#follow').html(msg);
}返回的#follow 要单独写一个文件
CI 控制器要这样写:
function addfollow(){
$pid = $this->input->post('pid');
if($this->input->post('ajax')){
$data['pid'] = $pid;
$this->load->view('follow', $data);
}
}
你ajax返回的应该是当前返回数吧,你看看你follow的js代码里
success:function(msg){
$('#follow').html();
}这里应该是$('#follow').html(msg);吧