views:

31

answers:

4

Hi all,

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/xhtml1/DTD/xhtml1-transitional.dtd"&gt;    
    <html xmlns="http://www.w3.org/1999/xhtml"&gt;    
    <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"&gt;&lt;/script&gt;       
    <style type="text/css">    
    /* CSS Document */   
    /*PAGE LAYOUT*/
 0


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

A: 

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.

WoLpH
A: 

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...

Garis Suero
+1  A: 

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.

dhofstet
+2  A: 

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

Nick