Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!