Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion AJAX POST with jQuery cross Controller - Bad Request

Received: by 10.52.21.68 with SMTP id t4mr8120841vde.8.1336132716588;
        Fri, 04 May 2012 04:58:36 -0700 (PDT)
X-BeenThere: cake-php@googlegroups.com
Received: by 10.52.67.76 with SMTP id l12ls338095vdt.9.gmail; Fri, 04 May 2012
 04:58:18 -0700 (PDT)
Received: by 10.52.70.196 with SMTP id o4mr209408vdu.0.1336132698667;
        Fri, 04 May 2012 04:58:18 -0700 (PDT)
Date: Fri, 4 May 2012 04:58:16 -0700 (PDT)
From: jmail <ad...@jmail.pl>
To: cake-php@googlegroups.com
Message-ID: <30943801.97.1336132696875.JavaMail.geo-discussion-forums@vbep19>
Subject: [Cake 2.1.1] AJAX POST with jQuery cross Controller - Bad Request
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_95_4799696.1336132696872"

------=_Part_95_4799696.1336132696872
Content-Type: multipart/alternative; 
	boundary="----=_Part_96_3645372.1336132696872"

------=_Part_96_3645372.1336132696872
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Hi!

I've got application which I am translating from other technology to 
CakePHP. Application is in about 60% written with AJAX.There are a lot of 
cross controller sends :/ So I've got a problem because when I am trying to 
make something similar with Cake I get error 400 - bad request. Of course I 
am using Security component and I would like to use this component. App 
it's quite secure with that component. Of course when I am using GET 
request everything is OK, but when try to use POST request there is a 
problem. 

I've got Controller MainController with function start

class MainController extends AppController{
function start(){
$this->set('contests', $this->Contest->find('all', array('conditions' => 
array('Contest.start <= now()', 'Contest.finish > now()', 'Contest.active' 
=> 1, 'Board.status' => 1))));
if(CakeSession::read('user') === null){
$this->layout = 'nonloginlayout';
}
else{
                        $this->render('startlogged');
}
}
}

Then in startlogged.ctp I've got script:

        function moreChances(){
$.prompt.close();
$.prompt(states, {zIndex: 11000});
$.ajax({
url: "/user/invite/"
,async: true
,dataType: "html"
,type: "GET"
,success: function(data){
$.prompt.close();
$.prompt(data, {buttons:{}, zIndex: 11000})
 }

});
}
 function sendInvite(){
mail = document.getElementById('inviteMail').value;
message = document.getElementById('inviteMessage').value;
$.prompt.close();
$.prompt(states, {zIndex: 11000});
$.ajax({
url: "/user/send_invite?tmp="+Math.random()
,async: false
,data: {test:'doopa'}
,type: "POST"
,dataType: "html"
,success: function(data){
$('#deb').html(data); 
}
,error: function(jqXHR, textStatus, errorThrown){
$('#deb').html(errorThrown);
}
});
       }


user/invite just loading a form into a prompt window


        <label>Email address:<br></label>
<input type="text" name="mail" id="inviteMail">
<br>
<label>Message:<br></label>
<textarea name="message" id="inviteMessage"></textarea>
<br><br>
<div class="floatRight">
<a href="javascript:sendInvite()" style="color: #636363;"><b>send</b></a>
</div>

and User controller look like this

class UserController extends AppController{

function beforeFilter() {
parent::beforeFilter();
$json_actions = array('send_invite');
if(in_array($this->action, $json_actions)){
$this->Security->validatePost = false = array('Session', 'RequestHandler', 
'ImageConverter');
}
}
 function invite(){
$this->layout = '';
}
 function send_invite(){
$this->autoRender = false;
var_dump($_POST);
}
}

And I don't know what to do more. Every POST request generating error:

2012-05-04 13:54:27 Error: [BadRequestException] The request has been 
black-holed
#0 
!!!Path_to_root!!!\lib\Cake\Controller\Component\SecurityComponent.php(227): 
SecurityComponent->blackHole(Object(UserController), 'csrf')


Can some please help me? I don't know what to do to not get black-holed. I 
am desperate because of that three of my projects are stoped :(

Thanks for all.

------=_Part_96_3645372.1336132696872
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi!<div><br></div><div>I've got application which I am translating from oth=
er technology to CakePHP. Application is in about 60% written with AJAX.The=
re are a lot of cross controller sends :/ So I've got a problem because whe=
n I am trying to make something similar with Cake I get error 400 - bad req=
uest. Of course I am using Security component and I would like to use this =
component. App it's quite secure with that component. Of course when I am u=
sing GET request everything is OK, but when try to use POST request there i=
s a problem.&nbsp;</div><div><br></div><div>I've got Controller MainControl=
ler with function start</div><div><br></div><div><div><font face=3D"'courie=
r new', monospace">class MainController extends AppController{</font></div>=
<div><font face=3D"'courier new', monospace"><span class=3D"Apple-tab-span"=
 style=3D"white-space:pre">=09</span>function start(){</font></div><div><fo=
nt face=3D"'courier new', monospace"><span class=3D"Apple-tab-span" style=
=3D"white-space:pre">=09=09</span>$this-&gt;set('contests', $this-&gt;Conte=
st-&gt;find('all', array('conditions' =3D&gt; array('Contest.start &lt;=3D =
now()', 'Contest.finish &gt; now()', 'Contest.active' =3D&gt; 1, 'Board.sta=
tus' =3D&gt; 1))));</font></div><div><font face=3D"'courier new', monospace=
"><span class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09</span>if(=
CakeSession::read('user') =3D=3D=3D null){</font></div><div><font face=3D"'=
courier new', monospace"><span class=3D"Apple-tab-span" style=3D"white-spac=
e:pre">=09=09=09</span>$this-&gt;layout =3D 'nonloginlayout';</font></div><=
div><font face=3D"'courier new', monospace"><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">=09=09</span>}</font></div><div><font face=3D"'co=
urier new', monospace"><span class=3D"Apple-tab-span" style=3D"white-space:=
pre">=09=09</span>else{</font></div><div><span style=3D"font-family: 'couri=
er new', monospace; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbs=
p; &nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;render('startlogged');</span><br><=
/div><div><font face=3D"'courier new', monospace"><span class=3D"Apple-tab-=
span" style=3D"white-space:pre">=09=09</span>}</font></div><div><font face=
=3D"'courier new', monospace"><span class=3D"Apple-tab-span" style=3D"white=
-space:pre">=09</span>}</font></div><div><span style=3D"font-family: 'couri=
er new', monospace; ">}</span><br></div></div><div><span style=3D"font-fami=
ly: 'courier new', monospace; "><br></span></div><div><font face=3D"arial, =
sans-serif">Then in startlogged.ctp I've got script:</font></div><div><span=
 style=3D"font-family: 'courier new', monospace; "><br></span></div><div><d=
iv><font face=3D"'courier new', monospace">&nbsp; &nbsp; &nbsp; &nbsp; func=
tion moreChances(){</font></div><div><font face=3D"'courier new', monospace=
"><span class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09</span>$.p=
rompt.close();</font></div><div><font face=3D"'courier new', monospace"><sp=
an class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09</span>$.prompt=
(states, {zIndex: 11000});</font></div><div><font face=3D"'courier new', mo=
nospace"><span class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09</s=
pan>$.ajax({</font></div><div><font face=3D"'courier new', monospace"><span=
 class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09=09</span>url: "/=
user/invite/"</font></div><div><font face=3D"'courier new', monospace"><spa=
n class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09=09</span>,async=
: true</font></div><div><font face=3D"'courier new', monospace"><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">=09=09=09</span>,dataType: "h=
tml"</font></div><div><font face=3D"'courier new', monospace"><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">=09=09=09</span>,type: "GET"<=
/font></div><div><font face=3D"'courier new', monospace"><span class=3D"App=
le-tab-span" style=3D"white-space:pre">=09=09=09</span>,success: function(d=
ata){</font></div><div><font face=3D"'courier new', monospace"><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">=09=09=09=09</span>$.prompt.c=
lose();</font></div><div><font face=3D"'courier new', monospace"><span clas=
s=3D"Apple-tab-span" style=3D"white-space:pre">=09=09=09=09</span>$.prompt(=
data, {buttons:{}, zIndex: 11000})</font></div><div><span class=3D"Apple-ta=
b-span" style=3D"white-space:pre"><font face=3D"'courier new', monospace">=
=09=09=09=09</font></span></div><div><font face=3D"'courier new', monospace=
"><span class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09=09</span>=
}</font></div><div><font face=3D"'courier new', monospace"><br></font></div=
><div><font face=3D"'courier new', monospace"><span class=3D"Apple-tab-span=
" style=3D"white-space:pre">=09=09</span>});</font></div><div><font face=3D=
"'courier new', monospace"><span class=3D"Apple-tab-span" style=3D"white-sp=
ace:pre">=09</span>}</font></div><div><span class=3D"Apple-tab-span" style=
=3D"white-space:pre"><font face=3D"'courier new', monospace">=09</font></sp=
an></div><div><font face=3D"'courier new', monospace"><span class=3D"Apple-=
tab-span" style=3D"white-space:pre">=09</span>function sendInvite(){</font>=
</div><div><font face=3D"'courier new', monospace"><span class=3D"Apple-tab=
-span" style=3D"white-space:pre">=09=09</span>mail =3D document.getElementB=
yId('inviteMail').value;</font></div><div><font face=3D"'courier new', mono=
space"><span class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09</spa=
n>message =3D document.getElementById('inviteMessage').value;</font></div><=
div><font face=3D"'courier new', monospace"><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">=09=09</span>$.prompt.close();</font></div><div><=
font face=3D"'courier new', monospace"><span class=3D"Apple-tab-span" style=
=3D"white-space:pre">=09=09</span>$.prompt(states, {zIndex: 11000});</font>=
</div><div><font face=3D"'courier new', monospace"><span class=3D"Apple-tab=
-span" style=3D"white-space:pre">=09=09</span>$.ajax({</font></div><div><fo=
nt face=3D"'courier new', monospace"><span class=3D"Apple-tab-span" style=
=3D"white-space:pre">=09=09=09</span>url: "/user/send_invite?tmp=3D"+Math.r=
andom()</font></div><div><font face=3D"'courier new', monospace"><span clas=
s=3D"Apple-tab-span" style=3D"white-space:pre">=09=09=09</span>,async: fals=
e</font></div><div><font face=3D"'courier new', monospace"><span class=3D"A=
pple-tab-span" style=3D"white-space:pre">=09=09=09</span>,data: {test:'doop=
a'}</font></div><div><font face=3D"'courier new', monospace"><span class=3D=
"Apple-tab-span" style=3D"white-space:pre">=09=09=09</span>,type: "POST"</f=
ont></div><div><font face=3D"'courier new', monospace"><span class=3D"Apple=
-tab-span" style=3D"white-space:pre">=09=09=09</span>,dataType: "html"</fon=
t></div><div><font face=3D"'courier new', monospace"><span class=3D"Apple-t=
ab-span" style=3D"white-space:pre">=09=09=09</span>,success: function(data)=
{</font></div><div><font face=3D"'courier new', monospace"><span class=3D"A=
pple-tab-span" style=3D"white-space:pre">=09=09=09=09</span>$('#deb').html(=
data);<span class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09=09</s=
pan></font></div><div><font face=3D"'courier new', monospace"><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">=09=09=09</span>}</font></div=
><div><font face=3D"'courier new', monospace"><span class=3D"Apple-tab-span=
" style=3D"white-space:pre">=09=09=09</span>,error: function(jqXHR, textSta=
tus, errorThrown){</font></div><div><font face=3D"'courier new', monospace"=
><span class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09=09=09</spa=
n>$('#deb').html(errorThrown);</font></div><div><font face=3D"'courier new'=
, monospace"><span class=3D"Apple-tab-span" style=3D"white-space:pre">=09=
=09=09</span>}</font></div><div><font face=3D"'courier new', monospace"><sp=
an class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09</span>});</fon=
t></div><div><span style=3D"font-family: 'courier new', monospace; ">&nbsp;=
 &nbsp; &nbsp; &nbsp;}</span><br></div></div><div><span style=3D"font-famil=
y: 'courier new', monospace; "><br></span></div><div><span style=3D"font-fa=
mily: 'courier new', monospace; "><br></span></div><div><font face=3D"arial=
, sans-serif">user/invite just loading a form into a prompt window</font></=
div><div><font face=3D"'courier new', monospace"><br></font></div><div><fon=
t face=3D"'courier new', monospace"><br></font></div><div><div style=3D"fon=
t-family: 'courier new', monospace; ">&nbsp; &nbsp; &nbsp; &nbsp; &lt;label=
&gt;Email address:&lt;br&gt;&lt;/label&gt;</div><div style=3D"font-family: =
'courier new', monospace; "><span class=3D"Apple-tab-span" style=3D"white-s=
pace:pre">=09</span>&lt;input type=3D"text" name=3D"mail" id=3D"inviteMail"=
&gt;</div><div style=3D"font-family: 'courier new', monospace; "><span clas=
s=3D"Apple-tab-span" style=3D"white-space:pre">=09</span>&lt;br&gt;</div><d=
iv style=3D"font-family: 'courier new', monospace; "><span class=3D"Apple-t=
ab-span" style=3D"white-space:pre">=09</span>&lt;label&gt;Message:&lt;br&gt=
;&lt;/label&gt;</div><div style=3D"font-family: 'courier new', monospace; "=
><span class=3D"Apple-tab-span" style=3D"white-space:pre">=09</span>&lt;tex=
tarea name=3D"message" id=3D"inviteMessage"&gt;&lt;/textarea&gt;</div><div =
style=3D"font-family: 'courier new', monospace; "><span class=3D"Apple-tab-=
span" style=3D"white-space:pre">=09</span>&lt;br&gt;&lt;br&gt;</div><div st=
yle=3D"font-family: 'courier new', monospace; "><span class=3D"Apple-tab-sp=
an" style=3D"white-space: pre; ">=09</span>&lt;div class=3D"floatRight"&gt;=
<br></div><div style=3D"font-family: 'courier new', monospace; "><span clas=
s=3D"Apple-tab-span" style=3D"white-space:pre">=09=09</span>&lt;a href=3D"j=
avascript:sendInvite()" style=3D"color: #636363;"&gt;&lt;b&gt;send&lt;/b&gt=
;&lt;/a&gt;</div><div style=3D"font-family: 'courier new', monospace; "><sp=
an class=3D"Apple-tab-span" style=3D"white-space:pre">=09</span>&lt;/div&gt=
;</div><div style=3D"font-family: 'courier new', monospace; "><br></div><di=
v><font face=3D"arial, sans-serif">and User controller look like this</font=
></div><div style=3D"font-family: 'courier new', monospace; "><br></div><di=
v><div><font face=3D"'courier new', monospace">class UserController extends=
 AppController{</font></div><div><font face=3D"'courier new', monospace"><b=
r></font></div><div><font face=3D"'courier new', monospace"><span class=3D"=
Apple-tab-span" style=3D"white-space:pre">=09</span>function beforeFilter()=
 {</font></div><div><font face=3D"'courier new', monospace"><span class=3D"=
Apple-tab-span" style=3D"white-space:pre">=09=09</span>parent::beforeFilter=
();</font></div><div><font face=3D"'courier new', monospace"><span class=3D=
"Apple-tab-span" style=3D"white-space:pre">=09=09</span>$json_actions =3D a=
rray('send_invite');</font></div><div><font face=3D"'courier new', monospac=
e"><span class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09</span>if=
(in_array($this-&gt;action, $json_actions)){</font></div><div><font face=3D=
"'courier new', monospace"><span class=3D"Apple-tab-span" style=3D"white-sp=
ace:pre">=09=09=09</span>$this-&gt;Security-&gt;validatePost =3D false =3D =
array('Session', 'RequestHandler', 'ImageConverter');</font></div><div><fon=
t face=3D"'courier new', monospace"><span class=3D"Apple-tab-span" style=3D=
"white-space:pre">=09=09</span>}</font></div><div><font face=3D"'courier ne=
w', monospace"><span class=3D"Apple-tab-span" style=3D"white-space:pre">=09=
</span>}</font></div><div><span class=3D"Apple-tab-span" style=3D"white-spa=
ce:pre"><font face=3D"'courier new', monospace">=09</font></span></div><div=
><font face=3D"'courier new', monospace"><span class=3D"Apple-tab-span" sty=
le=3D"white-space:pre">=09</span>function invite(){</font></div><div><font =
face=3D"'courier new', monospace"><span class=3D"Apple-tab-span" style=3D"w=
hite-space:pre">=09=09</span>$this-&gt;layout =3D '';</font></div><div><fon=
t face=3D"'courier new', monospace"><span class=3D"Apple-tab-span" style=3D=
"white-space:pre">=09</span>}</font></div><div><span class=3D"Apple-tab-spa=
n" style=3D"white-space:pre"><font face=3D"'courier new', monospace">=09</f=
ont></span></div><div><font face=3D"'courier new', monospace"><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">=09</span>function send_invit=
e(){</font></div><div><font face=3D"'courier new', monospace"><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">=09=09</span>$this-&gt;autoRe=
nder =3D false;</font></div><div><font face=3D"'courier new', monospace"><s=
pan class=3D"Apple-tab-span" style=3D"white-space:pre">=09=09</span>var_dum=
p($_POST);</font></div><div><font face=3D"'courier new', monospace"><span c=
lass=3D"Apple-tab-span" style=3D"white-space:pre">=09</span>}</font></div><=
div><span class=3D"Apple-tab-span" style=3D"white-space:pre"><font face=3D"=
'courier new', monospace">=09</font></span></div><div><font face=3D"'courie=
r new', monospace">}</font></div></div><div><font face=3D"'courier new', mo=
nospace"><br></font></div><div><font face=3D"arial, sans-serif">And I don't=
 know what to do more. Every POST request generating error:</font></div><di=
v><font face=3D"arial, sans-serif"><br></font></div><div><font face=3D"aria=
l, sans-serif"><div>2012-05-04 13:54:27 Error: [BadRequestException] The re=
quest has been black-holed</div><div>#0 !!!Path_to_root!!!\lib\Cake\Control=
ler\Component\SecurityComponent.php(227): SecurityComponent-&gt;blackHole(O=
bject(UserController), 'csrf')</div></font></div><div><font face=3D"arial, =
sans-serif"><br></font></div><div><font face=3D"arial, sans-serif"><br></fo=
nt></div></div><div><font face=3D"arial, sans-serif">Can some please help m=
e? I don't know what to do to not get black-holed. I am desperate because o=
f that three of my projects are stoped :(</font></div><div><font face=3D"ar=
ial, sans-serif"><br></font></div><div><font face=3D"arial, sans-serif">Tha=
nks for all.</font></div>
------=_Part_96_3645372.1336132696872--

------=_Part_95_4799696.1336132696872--