Question

I am trying to see if a table exists in this database using parsley remote validation, but I am not receiving the external php data, only 200 OK or 404 error codes. Is there any way to get the data I echo like 0 or 1 and compare it in the JS?

<input type="text" name="aux_tablas" data-parsley-remote data-parsley-remote-validator="aux_tablas" data-parsley-remote-options='{ "type": "GET", "dataType": "jsonp", "data": { "tipo": "aux_tablas" } }' />


<script type="text/javascript">
$('#form_principal').parsley()
  .addAsyncValidator('aux_tablas', function (xhr) {
    return 404 === xhr.status;
  }, '<?=$datos_configuracion->path?>protected/motor/busqueda.php');
</script>

The external php is answering with 1 or 0 and that's working, but I don't know how to make it validate. Thanks in advance for the help.

Was it helpful?

Solution

Resolved. If exists answers with 200, so its invalid, if not exists, works with 404, so:

In the external file, you should put if not exists header("HTTP/1.0 404 Not Found");

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top