用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1703|回复: 6
收起左侧

[HELP] Ajax 问题

[复制链接]
发表于 2013-9-6 15:29:08 | 显示全部楼层 |阅读模式
本帖最后由 shugong 于 2013-9-6 18:12 编辑

CI新手求教
PHP复制代码
function car_check(){
  $id     = $this->input->get('id');
  $da['carnum'] = $this->input->get('carnum');
  $da['color']  = $this->input->get('color');
 
  header("Content-Type:text/html;charset=gbk");  
  header("Cache-Control:no-cache");
  $info="";
  if($da['carnum'] == '')
  {
   $info= '{"res":" "}';
  }
  else{
   $res = $this->Mgate->edit_car_by_id($id, $da);
   if($res){
    $info= '{"res":"已核对"}';
   }
   else{
    $info= '{"res":"数据库出错"}';
   }
  }
  echo $info;
 }
复制代码

控制器
JS复制代码
 
function chuli(){
 if(myXmlHttpRequest.readyState==4){
       var mes=myXmlHttpRequest.responseText;
       window.alert(mes);
  }
 }
复制代码

ajax

alertHTML代码怎么去除呢

QQ截图20130906152624.png
 楼主| 发表于 2013-9-6 18:11:07 | 显示全部楼层
有高手能看下吗{:soso_e150:}
发表于 2013-9-7 08:19:14 | 显示全部楼层
你想前端返回的数据格式是什么样?json ???
PHP复制代码
function car_check(){
  $id     = $this->input->get('id');
  $da['carnum'] = $this->input->get('carnum');
  $da['color']  = $this->input->get('color');
 
  header("Content-Type:text/html;charset=gbk");  
  header("Cache-Control:no-cache");
  $info="";
  if($da['carnum'] == '')
  {
   $info= '{"res":" "}';
  }
  else{
   $res = $this->Mgate->edit_car_by_id($id, $da);
   if($res){
    $info= '{"res":"已核对"}';
   }
   else{
    $info= '{"res":"数据库出错"}';
   }
  }
  echo $info;
[color=Red]die();[b][/b][/color]
 }
复制代码
 楼主| 发表于 2013-9-7 21:04:05 | 显示全部楼层
对是JSON 但是后面有一大堆HTML代码怎么除去
发表于 2013-9-8 07:45:30 | 显示全部楼层
这是你开启了评测器造成的
发表于 2013-9-8 07:46:42 | 显示全部楼层
car_check() 这个方法里加
$this->output->enable_profiler(FALSE);
 楼主| 发表于 2013-9-8 09:57:55 | 显示全部楼层
xb0726 发表于 2013-9-8 07:46
car_check() 这个方法里加
$this->output->enable_profiler(FALSE);

还真是!非常感谢!

本版积分规则