使用Mootools从PHP读取返回值

使用Mootools从PHP读取返回值,php,ajax,mootools,Php,Ajax,Mootools,我一直在尝试通过AJAX检索数据。我似乎无法“读取”PHP发送给我的内容。这是密码 $('create_course').addEvent('submit', function(e){ e.stop(); flash.setStyle('display', 'none'); this.set('send', { onComplete: function(resp){ if ($chk(resp)) { console.log($typ

我一直在尝试通过AJAX检索数据。我似乎无法“读取”PHP发送给我的内容。这是密码

  $('create_course').addEvent('submit', function(e){
   e.stop();
   flash.setStyle('display', 'none');
   this.set('send', {
    onComplete: function(resp){
     if ($chk(resp))
     {
      console.log($type(resp));
      if (resp == 'true')
      {
       flash.set('html', resp);
       flash.reveal();
      }
      elseif (resp == 'false')
      {
       $$('div.information').dissolve();
       $$('div.options').reveal();
      }

     }
    }
   }).send();
  });
当我收到一个真的和一个假的不同动作时,会发生不同的动作

这就是密码

if(is_ajax())
{
如果($this->form\u validation->run('course\u create')==TRUE)
{
$course=数组(
'name'=>this->input->post('name'),
'description'=>this->input->post('desc'),
“价格”=>$this->input->post('price')
);
如果($this->course->create($course))
{
回声“真”;
}
其他的
{
回声“假”;
}
}
其他的
{
回波验证错误(“”、“

”); } }
注意:我已经修改了php和js,以便只读取是否有响应。这个php和js就是以前的样子。我的问题是,如果添加一个

alert(res);
它给了你什么

而不是

if ($this->course->create($course))
    {
     echo 'true';
    }
    else
    {
     echo 'false';
    }
你能做些什么

if ($this->course->create($course))
    {
     die 'true';
    }
    else
    {
     die 'false';
    }

我已经解决了。我想。我使用了Element.match()


你能给我们看一下php代码吗?我从来没有用alert检查过,但是console.log给我一个trueyes,但是你正在做
$type(resp)
我更喜欢
console.log(resp)在我考虑查看类型之前,我已经这样做了。它给了我'true',没有引号。so
console.log(resp=='true')给予?是的。我不明白的是为什么条件状态不起作用。
if ($this->course->create($course))
    {
     die 'true';
    }
    else
    {
     die 'false';
    }
$('create_course').addEvent('submit', function(e){
            e.stop();
            flash.setStyle('display', 'none');
            this.set('send', {
                onComplete: function(resp){

                    var is_validated = resp.match("true");

                    if (is_validated)
                    {
                        flash.set('html', resp);
                        flash.reveal();
                    }
                    else
                    {
                        $$('div.information').dissolve();
                        $$('div.options').reveal();
                    }
                }
            }).send();
        });