0

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
10
  • "anonymous function" is not an error (message), if at all, that's the location where an error occurred. Commented Jun 13, 2014 at 15:44
  • yes but, when I did a debug always get error in that point where never goes validate_form, I update the error complete. Commented Jun 13, 2014 at 15:49
  • This is not a valid URL for ajax request: %3C?php%20echo%20Router::Ur…pass%27][0],%201%20=%3E%20$this-%3Erequest-%3Eparams[%27pass%27][1]));?%3E Commented Jun 13, 2014 at 16:22
  • You cannot execute php code inside a javascript file, fix these issues Commented Jun 13, 2014 at 16:26
  • yes I now for these reason I explain that use before and after use this code php, and the 3 ways to try gives me the same error. Commented Jun 13, 2014 at 16:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.