Well,
The problem is that I always get the same error "anonymous function" is because when I want to send data via post these never find the Controller or the path to the Controller, I have proven with three ways to send data in the JS.
validate.js
$(document).ready(function(){
var route ="<?php echo Router::Url(array('controller' => 'soyaproductorcompras','action' => 'validate_form', 0 => $this->request->params['pass'][0], 1 => $this->request->params['pass'][1]));?>";
$('#proveedor_carnet').blur(function(){
$.post(route,
{
field: $('#proveedor_carnet').attr('id'),
value: $('#proveedor_carnet').val()
},
handleNmeValidation
);
});
function handleNmeValidation(error){
if(error.length > 0){
if($('#proveedor_carnet-notempty').length === 0){
$('#proveedor_carnet').after('<div id="proveedor_carnet-notEmpty" class="error-message">' + error + '</div>');
}
}else{
$('#proveedor_carnet-notEmpty').remove();
}
}
});
here Ihave the code that I am Using for my validation the problem is the route.
first option:
var route ='/cake/soyaproductorcompras/validate_form';
second option
var route ='http://localhost:8080/cake/soyaproductorcompras/validate_form';
and the last
var route ="<?php echo Router::Url(array('controller' => 'soyaproductorcompras','action' => 'validate_form', 0 => $this->request->params['pass'][0], 1 => $this->request->params['pass'][1]));?>";
I see similar problems but do not apply, like this.
this is the controller validate form:
public function validate_form()
{
$this->loadModel('SoyaProductorCompra');
$this->loadModel('SoyaProveedor');
$this->autoRender = FALSE;
if ($this->request->is('ajax')) {
$proveedor=$this->data['SoyaProductorCompra'][$this->params['form']['field']]=$this->params['form']['value'];
$existe = $this->SoyaProveedor->find(
'first',
array(
'fields' => array(
'SoyaProveedor.id'
),
'conditions' => array(
'SoyaProveedor.id' => $proveedor
)
)
);
if(empty($existe)){
//return false;
echo "no existe el usuario";
}else{
//return true;
echo "el usuario existe";
}
}
}
error complete
POST http://localhost:8080/cake/soyaproductorcompras/%3C?php%20echo%20Router::Ur…pass%27][0],%201%20=%3E%20$this-%3Erequest-%3Eparams[%27pass%27][1]));?%3E 404 (Not Found) jquery.js:9666
jQuery.ajaxTransport.send jquery.js:9666
jQuery.extend.ajax jquery.js:9211
jQuery.each.jQuery.(anonymous function) jquery.js:9357
(anonymous function) VM811 validation.js:4
jQuery.event.dispatch jquery.js:4624
jQuery.event.add.elemData.handle