关于ajax操作的个人理解
发布时间:2020-12-16 01:42:26 所属栏目:百科 来源:网络整理
导读:操作: input type="button" name="" class="btn" id="clearBtn" value="清空" 前端代码: $('#clearBtn').click(function(){$.ajax({type:'post',url:'index.php?act=groupbuyop=slider_clear',dataType:'json',success:function(result){if(result.result)
操作: <input type="button" name="" class="btn" id="clearBtn" value="清空"> 前端代码: $('#clearBtn').click(function(){ $.ajax({ type:'post',url:'index.php?act=groupbuy&op=slider_clear',dataType:'json',success:function(result){ if(result.result){ alert('清空成功'); location.reload(); } } }); }); 后端代码: /** *幻灯片清除 */ publicfunctionslider_clearOp(){ $model_setting=Model('setting'); $update=array(); $update['live_pic1']=''; $update['live_link1']=''; $update['live_pic2']=''; $update['live_link2']=''; $update['live_pic3']=''; $update['live_link3']=''; $update['live_pic4']=''; $update['live_link4']=''; $res=$model_setting->updateSetting($update); if($res){ dkcache('setting'); $this->log('清空幻灯片设置',1); echojson_encode(array('result'=>'true')); }else{ echojson_encode(array('result'=>'false')); } exit; } ajax返回来的数据有的时候是json字符串需要将其转化为json对象 alldata = eval('(' + data + ')'); 选择框的ajax $(function(){ selectajax(); $('#inform_type').on('change',(function(){ selectajax(); })); functionselectajax(){ id=$('#inform_type').val(); $.ajax({ type:'post',url:"index.php?act=member_inform&op=selectAjax",data:{id:id},success:function(data){ varlen=(data.length); $('#inform_subject').empty(); for(vari=0;i<len;i++){ $('#inform_subject').append("<optionvalue=""+data[i]["inform_subject_id"]+"">"+data[i]["inform_subject_content"]+"</option>"); } } }); } } 后端代码: <?php publicfunctionselectAjaxOp(){ $id=$_POST['id']; $inform_subject_model=Model('inform_subject'); $inform_subject=$inform_subject_model->getSubjectList(array('inform_type_id'=>$id),'inform_subject_id,inform_subject_content'); echojson_encode($inform_subject); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |