2012-04-23 146 views
0

我发布了一些用于注册到CakePHP控制器操作的表单值。该代码是这样的AJAX发布到CakePHP控制器操作

var params='firstname='+encodeURIComponent(firstname) +'&lastname='+encodeURIComponent(lastname)+'&emailid='+encodeURIComponent(emailid)+'&password='+encodeURIComponent(password); 

xmlhttp.open('POST', url, true); 
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
xmlhttp.send(params); 

这是做发布,我可以在POST节源看到它的萤火虫作为

firstname=name&lastname=name&emailid=mymailid&password=123123 

但是,当我在行动打印$这个 - >数据,它不会显示任何值。我甚至使用$ _POST,它也返回任何东西..

我在这里做了什么错误..?

回答

0

你缺少一个使用POST发送变量时所需的请求头:

试试这个:在控制器

var params='firstname='+encodeURIComponent(firstname) +'&lastname='+encodeURIComponent(lastname)+'&emailid='+encodeURIComponent(emailid)+'&password='+encodeURIComponent(password); 

xmlhttp.open('POST', url, true); 
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
xmlhttp.setRequestHeader("Content-length", params.length); 
xmlhttp.send(params); 
+0

我已经添加了它并使用了$ this-> params ['url'];和$ this-> request ['url'];第一个只显示我发布的URL,第二个没有显示任何内容。 – 2012-04-24 05:43:10

0

尝试像以下:

$this->params['url']; // this will give an array of parameters 

或者, $this->request['url']; // this will give an array of parameters

相关问题