It is unclear to me what the route to your delete controller is. I will assume "/Pys/{pysStr}" with route name "my_pys". Also your current "pysStr" should be available as variable in your twig template. Assuming in your display controller you put:
'currentPysStr' => $pysStr (put this in the render method are argument)
$('a').on('click', function(e) {
if( ! $('#criTitulo').val() || ! $('#criContenido').val() ) {
if ( ! $('#criTitulo').val() && $('#criContenido').val() ) {
if(! window.confirm( 'Falta el titulo' )) {
e.preventDefault();
} else {
$.get({{ path('my_pys', {'pysStr': currentPysStr}) }})
}
}
else if ( ! $('#criContenido').val() && $('#criTitulo').val() ) {
return confirm('Falta el contenido');
}
}
});
Then in your delete controller you will have the current PysStr and this controller will only be called when you press OK in the confirmation dialog.
The same as in your order question you have a choice if you want to put this script in a twig template or use a global variable. ( https://stackoverflow.com/questions/18035337/translate-the-jeditable-plugins-attributes/18035436#18035436 )
EDIT: (after chat)
$('a').on('click', function(e) {
var titulo = $('#criTitulo').val(),
contenido = $('#criContenido').val();
console.log(titulo);
console.log(contenido);
// Requested: XOR
// One of the values must be set, the other one must not be set
if ( ( titulo && !contenido ) || ( !titulo && contenido ) ) {
e.preventDefault();
console.log('Link clicked !');
if (window.confirm( 'Falta el titulo' )) {
var ajax;
var url = Routing.generate('eliminar_critica.' + $('html').attr('lang'), { "_locale": $('html').attr('lang'), "pysStr": $('section').attr('pelicula') });
console.log(url); // This is just here for debugging purposes
ajax = $.get(url);
ajax.done(function() {
window.location.href = $(e.target).attr('href');
});
}
}
});
Placing window.location.href
in done()
guarantees the request was made before the page refresh
eliminarCriticaAction
should give a Response that everything went on (2**) response. 204 is appropriate like this:
return new response('', 204); // 204: No Content