javascript - send data from cakephp view to controller using $.ajax post -
I am using $ .jax for the first time in CakePhp2.4.5 - I read many posts on stack overflow and others Research on W3schools and jquery sites but I could not understand how to solve my problem. I want to send my first view to data controller from index.ctp
$ .ajax ({type : 'POST', url: 'meers / client', datatype: 'jason', cache: incorrect, data: {myVal: 'success!'}, Success: work () {warning ('AjaX success')}, error : Action () {Warning (' AjaX failed ')}}). () {Warning ('AJX Done!');}); Public function client () (if ($$) - & gt; Request-> isAjax ()) {$ this- & gt; Set ('ajaxTest', 'success'); }}
My second view is in client.ctp.
if (isset ($ ajaxTest)) {echo $ ajaxTest; } Else {echo 'ajaxTest not set'. '; } The problem is that I always get the msg in my client. ACP View "The executor is not set" What am I doing wrong? Or how to do it? Thank you
I think the problem is in the URL because there is no route in 'Mirs / Client'
$ .ajax ({type: 'POST', url: "& lt ;? php echo $ this-> html-> URL (array ('controller' = & Gt; 'YourController', 'Action' => 'Action' =>);; & gt; ", Datatype: 'Jason', Cache: Wrong, Data: {myVal: 'Success!'}, Success: Work () (Warning ('ajx success')}, error: function () {alerts ('ajax fail')}} .one (function () {alerts ('ajax done!');}); or You can check the extortion:
$ .ajax ({type: 'POST', url: "& lt ?? php echo router :: URL (array ('controller' = & Gt; 'Your Controller', 'Action' = & gt; Your Action '), True);; & gt; ", Datatype:' Jason ', Cache: Wrong, Data: {myVal:' Success! '}, Success: Action () (Warning ('Ajax Success')}, Error: Work () {Warning ('Azax Fail')}}) .Done (function () {Warning ('AJX Done!');}); You
Comments
Post a Comment