I trying to do a validation by ajax and php, this is my ajax code:
function PrintRecibopapel()
{
recibo = document.getElementById("txtCod").value;
if(recibo == "")
{
alert("Debe Guardar el recibo antes de imprimir");
}
else
{
//ImprimirPDF("modulos/reporte/ingresos/RPrintReciboPapel.php?cods="+recibo);
$.ajax({
method: 'GET',
url: 'modulos/ingresos/actualizarIngreso.php',
data: {recibo: recibo}
})
}
}
The function PrintRecibopapel();
is in my form on an input with onclick
So, this is my php (other file):
<?php
include("../../libreria/engine.php");
$_SESSION["logError"] = array();
$recibo = $_GET["recibo"];
$sql = "UPDATE af_ing SET copia = 1 WHERE cod = '$recibo'";
$rs = mysql_query($sql);
?>
<script languaje= 'javascript'>
mostrarErrores();
actualizarPestana();
</script>
The error that the Google Chrome console is givin to me is this: VM2941:1 GET http://localhost/municipia1/modulos/ingresos/actualizarIngreso.php?recibo=2017-00090 404 (Not Found)
As you can see (at least me) is that the url is good and is passing the variable recibo
fine, Do I am doing something wrong?
AJAX paths to server-side scripts can either be relative or absolute. In this case you are making the AJAX call from the same directory location in which the server-side script lives. Since you are running both scripts from the same directory it would be easier to use a relative path and change the URL in your AJAX call to this:
url: 'actualizarIngreso.php',
As it stands now the AJAX call is looking for the following which is wrong and generates the 404 error:
municipia1/modulos/ingresos/municipia1/modulos/ingresos/actualizarIngreso.php
Many times developers will develop a central library of server-side scripts and put them in one location where they can receive calls from many locations. In that case you can use absolute path in your AJAX url
parameter:
url: 'http://hostname/municipia1/modulos/ingresos/actualizarIngreso.php',