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 36907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:28:01+00:00 2026-05-10T14:28:01+00:00

I have seen simple example Ajax source codes in many online tutorials. What I

  • 0

I have seen simple example Ajax source codes in many online tutorials. What I want to know is whether using the source code in the examples are perfectly alright or not?

Is there anything more to be added to the code that goes into a real world application?

What all steps are to be taken to make the application more robust and secure?

Here is a sample source code I got from the web:

function getChats() {     xmlHttp=GetXmlHttpObject();     if (xmlHttp==null) {             return;     }      var url='getchat.php?latest='+latest;        xmlHttp.onreadystatechange=stateChanged;     xmlHttp.open('GET',url,true);     xmlHttp.send(null); }   function GetXmlHttpObject() {     var xmlHttp=null;     try {             xmlHttp=new XMLHttpRequest();     } catch (e) {             try {                     xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');             } catch (e) {                     xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');             }     }     return xmlHttp; } 
  • 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. 2026-05-10T14:28:02+00:00Added an answer on May 10, 2026 at 2:28 pm

    The code you posted is missing one important ingredient: the function stateChanged.

    If you don’t quite understand the code you posted yourself, then what happens is when the call to getchats.php is complete, a function ‘stateChanged’ is called and that function will be responsible for handling the response. Since the script you’re calling and the function itself is prefixed with ‘gets’ then I’m pretty sure the response is something you’re going to be interested in.

    That aside, there are a number of ways to improve on the code you posted. I’d guess it works by declaring a single ‘xmlHttp’ object and then making that available to every function (because if it doesn’t, the stateChanged function has no way of getting the response). This is fine until you run an AJAX request before the last one (or last few) haven’t replied yet, which in that case the object reference is overwritten to the latest request each time.

    Also, any AJAX code worth its salt provides functionality for sucess and failure (server errors, page not found, etc.) cases so that the appriopiate message can be delivered to the user.

    If you just want to use AJAX functionality on your website then I’d point you in the direction of jQuery or a similar framework.

    BUT if you actually want to understand the technology and what is happening behind the scenes, I’d continue doing what you’re doing and asking specific questions as you try to build a small lightweight AJAX class on your own. This is how I done it, and although I use the jQuery framework today.. I’m still glad I know how it works behind the scenes.

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

Sidebar

Ask A Question

Stats

  • Questions 117k
  • Answers 117k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't know about chrome, but I believe that IE7… May 11, 2026 at 10:48 pm
  • Editorial Team
    Editorial Team added an answer Are you missing a bracket? update forge..dimInteg2 set duplicates =… May 11, 2026 at 10:48 pm
  • Editorial Team
    Editorial Team added an answer You can use the IsSharedSizeScope attached property. In your template… May 11, 2026 at 10:48 pm

Related Questions

I'm working on a mvc application that uses jquery to implement dynamically loading page
I have seen samples of closure from - What is a 'Closure'? Can anyone
I've seen a lot of different takes on this subject so I figured if
What do you think are the difference in mindset between a programmer doing work

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.