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

c# - passing input text from view to contoller with FacebookContext using Facebook app -

ios - Does Core Data autoupdate a many to many relationship on saving -

Calling a C++ function from C# by passing a string with variable size to it -