代码之家  ›  专栏  ›  技术社区  ›  Teej

使用moootools从php读取返回值

  •  0
  • Teej  · 技术社区  · 15 年前

    我一直试图通过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())
      {
       if ($this->form_validation->run('course_create') === TRUE)
       {
        $course = array(
         'name'  => $this->input->post('name'),
         'description'  => $this->input->post('desc'),
         'price' => $this->input->post('price')
        );
    
    
        if ($this->course->create($course))
        {
         echo 'true';
        }
        else
        {
         echo 'false';
        }
       }
       else
       {
        echo validation_errors('<div class="message error"><p>', '</p></div>');
       }
      }
    

    注意:我已经修改了PHP和JS,以便在有响应时读取。所以这个PHP和JS是过去的。我的重点是如何“读取”moools/js中的返回值。

    2 回复  |  直到 15 年前
        1
  •  1
  •   Teej    15 年前

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

    $('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();
            });
    
        2
  •  0
  •   RageZ    15 年前

    如果添加

    alert(res);
    

    它给你什么?

    而不是

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

    你能做吗?

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