开发者

JQuery AJAX returned too much data that I had not requested

开发者 https://www.devze.com 2023-01-03 18:35 出处:网络
I am using CakePHP 1.26 and CDN JQuery in this URL: http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js

I am using CakePHP 1.26 and CDN JQuery in this URL: http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js

In a HTML web page, I have these lines of code:

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

});

and in the PHP page, I got another few lines of code:

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

As you see, the Avail function will return either zero or one. But there was some redundant data returned from the server,

what I saw in the Alert box was somthing like this (rather than 0 or 1):

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    
    "http://www.w3.org/TR/开发者_StackOverflow社区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

No, it's not the missing Controller that caused the problem.


Or in your controller you can set $this->layout = ''; or $this->layout = 'ajax'; and you shouldn't get any other output.


Add the RequestHandler to the $components array of your controller. With that in place, Cake automatically uses the Ajax layout when there is an Ajax request.


It's telling you what's going wrong right?

<title>Missing Method in Controller</title>

So my guess is that Site1 or User does not exist.


The CakePHP returned an error page saying that the method you are invocating doesn't exist...

I suggest to try the URL without jquery, write it in the address bar and make it work...


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();

//get ur data in this array

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

}
0

精彩评论

暂无评论...
验证码 换一张
取 消