Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
Why return 404 error? javascript to refresh div

I'm trying to insert a script to make a div refresh with javascript/ajax. I found the following code. I don't put prova.asp page because it contains only a response.write "Hello" (then I will modify with database query). This code returns a 404 error and I do not understand why. The only URL is prova.asp and this file is in the same folder.

Anyone can tell me where I'm wrong? the mistake is mine but I don't know what it is.

<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script type="text/javascript">
        //If our user enters data in the username input, then we need to enable our button
        function OnChangedUsername(){
            if(document.form1.newuserid.value == ""){
                document.form1.btnCheckAvailability.disabled = true;
            }
            else
            {
                document.form1.btnCheckAvailability.disabled = false;
            }
        }

        function OnCheckAvailability(){
            if(window.XMLHttpRequest){
                oRequest = new XMLHttpRequest();
            }
            else if(window.ActiveXObject)
            {
                oRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }

            oRequest.open("POST", "prova.asp", true);
            oRequest.onreadystatechange = UpdateCheckAvailability;
            oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            oRequest.send("strCmd=availability&strUsername=" + document.form1.newuserid.value);
        }

        function UpdateCheckAvailability(){
            if(oRequest.readyState == 4){
                if(oRequest.status == 200){
                    document.getElementById("Available").innerHTML = oRequest.responseText;
                }
                else
                {
                    document.getElementById("Available").innerHTML = "Asynchronous Error";
                }
            }
        }
    </script>
  </head>
 <body>

<form method="post" action="javascript:void(0);" name="form1">
<table cellspacing="0">
<tr>
<th><label for="newuserid">Username:</label></th>
<td><input type="newuserid" name="newuserid" id="newuserid" size="20" onKeyUp="OnChangedUsername();"/></td>
<td><input id="btnCheckAvailability" type="button" disabled="disabled" value="Check Availability" onClick="OnCheckAvailability();"></td>
<td><div id="Available"></div></td>
</tr>
</table>
</form>

  </body>
</html>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Maybe, the browser try to first execute the script. Add your script before closing div tag.

<body>
...
...
<script .... >
.....
</script>
</body>

Or try to add defer

<body>
...
...
<script .... defer>
.....
</script>
</body>

Or async

<body>
...
...
<script .... async >
.....
</script>
</body>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda