0

我在这个 URL 中使用 CakePHP 1.26 和 CDN JQuery:http: //ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js

在 HTML 网页中,我有这些代码行:

 $.ajax({
      type: "POST",
      url: "http://mywebsite.com/controllers/avail/"+curl,   
      success: function(data) {         
      alert(data);}

});

在 PHP 页面中,我又得到了几行代码:

 function avail($uname){  
              $result1=$this->Site1->User->findByusername($uname);  
               if($result1){
                return 1;
                            }
               else{
                 return 0;
                   }
        }  

如您所见,Avail 函数将返回零或一。但是服务器返回了一些冗余数据,
我在警报框中看到的是这样的(而不是 0 或 1):

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    
    <html xmlns="http://www.w3.org/1999/xhtml">    
    <head>    
    <title>my site</title>    
    <meta http-equiv="content-type" content="text/html; charset=utf-8">  
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>       
    <style type="text/css">    
    /* CSS Document */   
    /*PAGE LAYOUT*/
 0


不,导致问题的不是缺少的控制器。

4

5 回答 5

3

或者在你的控制器中你可以设置$this->layout = ''; or $this->layout = 'ajax';并且你不应该得到任何其他输出。

于 2010-07-27T00:47:56.543 回答
1

将 添加RequestHandler$components控制器的数组中。有了这些,当有 Ajax 请求时,Cake 会自动使用 Ajax 布局。

于 2010-06-12T15:43:27.587 回答
0

它告诉你出了什么问题,对吗?

<title>Missing Method in Controller</title>

所以我的猜测是Site1或者User不存在。

于 2010-06-12T15:06:51.790 回答
0

CakePHP 返回一个错误页面,提示您调用的方法不存在...

我建议尝试不使用jquery的URL,将其写在地址栏中并使其工作...

于 2010-06-12T15:10:41.603 回答
0
ajaxFunction(){

$this->layout = 'ajax';
        Configure::write('debug', 0);
        if (!$this->RequestHandler->isAjax()) {
            $this->cakeError('error', array(
                array(
                    'code' => '404',
                    'name' => __('Page Not Found', true),
                    'message' => 'The Request URL does not exist on this server',
                    'title' => __('404', true),
                    'base' => $this->base,
                    'url' => $this->here
                )
            ));
            exit();
        }
            $response=array();

//在这个数组中获取你的数据

    $response['result'] = Configure::read('Ajax.success');
    $this->set('response',$response);
    $this->renderXhrView();

}
于 2011-07-12T05:51:38.687 回答