send data (POST) from jquery to controller in cakephp

send data (POST) from jquery to controller in cakephp

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:

POST http://localhost:8080/cake/soyaproductorcompras/ 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