This is my .ctp file where on the click of submit button it should save the data in database. But when the function is going on the controller it is not returning any value, so it is not going in the success function of ajax. And I have no idea whether it is going in the controller function and returning any value.
$('#submit_btn').click(function(e){
var value1=$('#nname').val();
//alert(value1);
$.ajax({
cache: false,
dataType: "html",
type: "POST",
evalScripts: true,
url: '<?php echo Router::url(array('controller'=>'Partconfs','action'=>'addlot'));?>',
data: ({name1:value1}),
success: function(result){
console.log(result);
alert(result);
if(result==2)
{
$('*').css('cursor','auto');
}
}
});
});
Associated .php file where I am simply saving the lot_no in the lot table in the database and echoing 2.so it should return to the success function of ajax.but there is some problem and it is not returning to ajax success function.
public function addlot()
{
$this->loadModel('lot');
$this->layout = 'ajax';
$this->autoRender = false;
$lotno=$this->request->data['name1'];
$loc = $this->Auth->user('location');
$acc=array('lot_no'=>$lotno,'location'=>$loc);
$this->lot->save($acc);
$this->loadModel('lot');
$this->lot->recursive=0;
$this->set('lots',$this->lot->find('all',array('conditions'=>array('location'=>$loc))));
echo 2;
}
First you need to change
url: '<?php echo Router::url(array('controller'=>'Partconfs','action'=>'addlot'));?>',
to
url: "<?php echo Router::url(array('controller'=>'Partconfs','action'=>'addlot'));?>",
and in order to debug your ajax you can check "Network" tab of your browser and choose your ajax call from there and check what error you are getting. Please find the attached image for your reference