Good day.
I have a question I couldn't solve it, I'm using Cakephp and $.ajax
. The data from $.ajax
can be passed in to my database. But the problem is I cant redirect to another page when successful.
I had tried the if($save){ echo something}
and is working, just the $this->redirect
part.
The Cakephp code as below:
public function testingadd() {
$this->layout=null;
$name = $_GET['name'];
$email = $_GET['email'];
$phone = $_GET['phone'];
$this->Newlead->create();
$this->Newlead->set("name",$name);
$this->Newlead->set("email",$email);
$this->Newlead->set("phone",$phone);
$save = $this->Newlead->save();
if($save)
{
$this->redirect('/Newlead/thankyou');
}
}
Ajax code as below:
$("#btn-submit").click(function ()
{
var obj = new Object();
obj.n = $("#inputName").val();
obj.e = $("#inputEmail").val();
obj.c = $("#inputMobile").val();
$.ajax({
type: 'POST',
url: '/Newleads/testingadd.json',
data: {
'name' : obj.n,
'email' : obj.e,
'phone' : obj.c
},
dataType: "jsonp",
timeout:1000,
jsonp:'jsonp'
});
});
Is there any more code need to be added to any files in Cakephp such as routes.php, PagesController.php or any? I'm still new to this. Please help.