Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6334895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:44:50+00:00 2026-05-24T18:44:50+00:00

i am practicing AJAX, in that i written a code to get the text

  • 0

i am practicing AJAX, in that i written a code to get the text from a file in server and if it is “0” print”zero” or print “one” if error print “not connected”. but something went wrong dont know what only getting not connected even if it is connected..

here is the code:

<html>
<head>
<title>LogIN</title>
<script>
function verify()
            {           
            var xml;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xml=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xml=new ActiveXObject("Microsoft.XMLHTTP");
  }
   xml.onreadystatechange=function()
       {
       if (xml.readyState==4 && xml.status==200)
        {
            var res=xml.responseText();
            if(res.equals("0"))
            {
                document.write("zero");
            }
            else
            {
            document.write("one");
            }
        }
        else
            document.write("Not connected");
        }
  xml.open("GET", "log_verify.txt", true);
  xml.send();
}
function login()
{
//action to login
}
</script>
</head>
<body>
<form>
User name : <input type="text" name="uname" onblur="verify()">
<br>
Pwd    : <input type="password" name="passwd" >
<br>
<input type="button" name="Login" value="Login" onclick="login()">
</form>
</body>
</html>

Getting the output as

Not connectedNot connectedNot connected

but when i just display the response text it gets printed correctly as per the code below

<html>
<head>
<title>LogIN</title>
<script>
function verify()
            {           
            var xml;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xml=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xml=new ActiveXObject("Microsoft.XMLHTTP");
  }
   xml.onreadystatechange=function()
  {
  if (xml.readyState==4 && xml.status==200)
    {
       document.getElementById("myDiv").innerHTML+=xml.responseText;
    }
  } 
  xml.open("GET", "log_verify.txt", true);
  xml.send();
}
function login()
{
//action to login
}
</script>
</head>
<body>
<form>
User name : <input type="text" name="uname" onblur="verify()">
<br>
Pwd    : <input type="password" name="passwd" >
<br>
<input type="button" name="Login" value="Login" onclick="login()">
</form>
<div id="myDiv"><h2>Response text:</h2></div>
</body>
</html>

Getting the output as

Response text:

0

is the problem in javascript coding or somewhere in server response??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:44:52+00:00Added an answer on May 24, 2026 at 6:44 pm

    First,

        else
            document.write("Not connected");
    

    is executed whenever the state changes and it the statusses aren’t 4 and 200. It does not necessarily mean Not connected. You could just remove that part. You are currently seeing it three times as the status changes from 0 to 1 to 2 to 3 (and 4 but that doesn’t go to the else).

    Secondly, you are using .equals but this function is not natively available and you also don’t have it defined. Are you looking for:

     if(res == "0")
    

    == is the equality operator. And,

    res = xml.responseText;
    

    it is not a function so you should not append ().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am practicing NHibernate recently and it does not look that much easy. (This
I'm practicing drawing polyline on the Map. I've adopted Sample code from download here.
While practicing the jxl API, i cant extract details from certain Excel sheet its
I'm practicing Jquery and I've written this simple Jquery statement: var someText = $(table
I'm practicing some file upload with PHP and I was uploading a file numerous
I am practicing recursion and I can't see why this method does not seem
I'm practicing writing MVC applications. I have a Mastermind game, that I would like
I am practicing with PHP and AJAX but I have some problems! I'm trying
Been practicing with those system calls, but I stucked into this code: #include <stdio.h>
I'm practicing some simple 2D game programming, and came up with a theory that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.