2012-04-23 15 views
0

登録に使用されるいくつかのフォーム値をcakePHPコントローラアクションにポストしています。コードは、このCakePHPコントローラへのAJAXポスト投稿アクション

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

これは、投稿を行っていると私は

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

としてPOSTセクションのソースでFirebugの中でそれを見ることができますが、のようなものです私はアクションでの$ this - >データを印刷するときそれは値を表示していません。私も$ _POSTを使っていて、何かを返すこともあります。

私はここで間違っていましたか?あなたは、変数を送信するためにPOSTを使用する場合に必要とされるリクエストヘッダが欠落している

答えて

0

代わりにこれを試してみてください。以下のようなコントローラで

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だけを表示し、もう1つは何も表示していません。 –

0

試してみてください。

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

かを、 $this->request['url']; // this will give an array of parameters

関連する問題