php - Redirect not working. $.ajax + Cakephp -


Good day.

I have a question that I could not solve it, I am using the cpp and $ 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.

I tried the 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'); }}   

Ajax code below:

  $ ("# 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'})});   

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

  public function testadd () {[...] if (save $) {return json_encode (array ('saveSuccess' =' & Gt; true)); }}   

Code on Customer

  $ Ajax ([...], datatype: 'Jason', success: work (data) {if (data.saveSuccess === 'true') {// redirect window. Location = '/ newlead / thanks';} }, Error: function () {warning ('an error occurred');}});    

Comments

Popular posts from this blog

How can I add a seperate action listener to all 14 of my buttons at once that can determine player turn?(java) -

php - Sorting an multidimension array using usort fails -

Simple file compression in C -