shugong 发表于 2013-9-6 15:29:08

Ajax 问题

本帖最后由 shugong 于 2013-9-6 18:12 编辑

CI新手求教
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;
}
控制器

function chuli(){
if(myXmlHttpRequest.readyState==4){
       var mes=myXmlHttpRequest.responseText;
       window.alert(mes);
}
}
ajax

alertHTML代码怎么去除呢

shugong 发表于 2013-9-6 18:11:07

有高手能看下吗{:soso_e150:}

57sy.com(隐身中 发表于 2013-9-7 08:19:14

你想前端返回的数据格式是什么样?json ???
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;
die();
}

shugong 发表于 2013-9-7 21:04:05

对是JSON 但是后面有一大堆HTML代码怎么除去

xb0726 发表于 2013-9-8 07:45:30

这是你开启了评测器造成的

xb0726 发表于 2013-9-8 07:46:42

car_check() 这个方法里加
$this->output->enable_profiler(FALSE);

shugong 发表于 2013-9-8 09:57:55

xb0726 发表于 2013-9-8 07:46 static/image/common/back.gif
car_check() 这个方法里加
$this->output->enable_profiler(FALSE);

还真是!非常感谢!
页: [1]
查看完整版本: Ajax 问题