php - Redirect not working. $.ajax + Cakephp -
Good day.
I have a question that I could not solve it, I am using the cpp and I tried the Ajax code below: Any code in routes.php , PagesController.php or any file should be added in the cake? I'm still new to this. help please. Route to JavaScript by visiting the client, depending on the response to your server: Code (controller) on the server Code on Customer $ AJAX . Data can be passed in my database from
$ .jax but the problem is that if I succeed I can not redirect to any other page.
if (save $$) {some echo} and is working, only
$ this-> Redirects part. As a cakefip code:
public function testadd () {$ this- & gt; Layout = zero; $ Name = $ _GET ['name']; $ Email = $ _GET ['email']; $ Phone = $ _GET ['phone']; $ This- & gt; Newlead- & gt; Create (); $ This- & gt; Newlead- & gt; Set ("name", $ name); $ This- & gt; Newlead- & gt; Set ("email", $ email); $ This- & gt; Newlead- & gt; Set ("phone", $ phone); Save $ = $ this- & gt; NewLade-> save (); If (Save $ $) {$ this- & gt; Redirect ('/ NewLead / Homesu'); }}
$ ("# btn-submit"). Click (function () {var obj = new object (); Obj.n = $ ("# inputName"). Val (); obj.e = $ ("# inputEmail"). Val (); obj.c = $ ("# InputMobile"). Val (); $ .aex ({type: 'post', url: '/ newlids / testing.jason', data: {'name': obj.n, 'email': Obj.e, 'phone': obj.c}, data type: "jsnp", timeout: 1000, jsnp: 'jsnp'})});
public function testadd () {[...] if (save $) {return json_encode (array ('saveSuccess' =' & Gt; true)); }}
$ Ajax ([...], datatype: 'Jason', success: work (data) {if (data.saveSuccess === 'true') {// redirect window. Location = '/ newlead / thanks';} }, Error: function () {warning ('an error occurred');}});
Comments
Post a Comment