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

The Archive Base Latest Questions

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

Could anyone explain me why: function doAjax() { var xmlHttpReq = false; try {

  • 0

Could anyone explain me why:

function doAjax() {     var xmlHttpReq = false;     try { // Firefox, Opera 8.0+ and Safari         xmlHttpReq = new XMLHttpRequest();     }     catch (e) { // Internet Explorer         try {             xmlHttpReq = new ActiveXObject('Msxml2.XMLHTTP');         }         catch (e) {             try {                 xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP');             }             catch (e) {                 alert('Your browser does not support AJAX. Please use an AJAX compatible browser.');                 return false;             }         }     }     xmlHttpReq.open('GET', 'handler.php', true);     xmlHttpReq.onreadystatechange = function() {         if (xmlHttpReq.readyState == 4) {             var response = xmlHttpReq.responseText;             handleAjaxResponse(response);         }     };     xmlHttpReq.send(null);     return true; } 

is causing the following validation errors:

Error:  Implied global: ActiveXObject 8, XMLHttpRequest 4, alert 15, handleAjaxResponse 24  Problem at line 10 character 16: 'e' is already defined.  catch (e) {  Problem at line 14 character 20: 'e' is already defined.  catch (e) { 

by the JSlint.com javascript validator

  • 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-10T23:43:01+00:00Added an answer on May 10, 2026 at 11:43 pm

    It would be more sensible to use framework like jQuery (especially if you seriously want to support older versions of IE (pre v6) ) but I’ll assume there is a reason you’re not doing that.

    It would be better if a) you don’t nest try-catches and b) you factored out a set of functions namely one to get an Xhr object, another to use an Xhr object to make a generic ajax request and an outer ‘doAjax’ function that performs the specific ajax call you want to make:-

    function getXHR() {     var result = null     if (window.XMLHttpRequest)     {         result = new XMLHttpRequest();     }     else     {         try { result = new ActiveXObject('MSXML2.XMLHTTP.3.0') }         catch (e) { }          if (result == null)         {             try { result = new ActiveXObject('Microsoft.XMLHTTP') }             catch (e) { }         }     }     return result;  }   function ajaxRequest(url, data, callBack) {     var xmlHttpReq = getXHR();     if (xmlHttpReq)     {         xmlHttpReq.open(data != null ? 'GET' : 'POST', url, true);         xmlHttpReq.onreadystatechange = function()         {             if (xmlHttpReq.readyState == 4)             {                 //what happens if status is not 200                 callBack(xmlHttpReq.responseText);             }         };         xmlHttpReq.send(null);         return true;     }     else     {         return false;     } }  function doAjax() {      var result = ajaxRequest('handler.php', null, handleAjaxResponse);      if (!result) alert('Your browser does not support AJAX. Please use an AJAX compatible browser.');      return result; } 

    A futher refinement would be to make the callback accept an XHR object rather than the basic responseText. This would give you more flexibility. If the callback function simply wants the text it can use this function:-

    function getTextFromXhr(xhr) {     xhr.onreadystatechange = fnVoid;     if (xhr.status == 200)     {         return xhr.responseText;     }     else     {         throw {number: xhr.status,             description: xhr.statusText,             responseText: xhr.responseText         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use this code:Improving SharePoint's SPListItemCollection GetDataTable(), let's get… May 12, 2026 at 2:18 pm
  • Editorial Team
    Editorial Team added an answer If your string is unique (and will always be unique),… May 12, 2026 at 2:18 pm
  • Editorial Team
    Editorial Team added an answer In addition to what's been pointed out already, I highly… May 12, 2026 at 2:18 pm

Related Questions

Could anyone explain me why the generics List.Contains() function is so slow? I have
I've spent the last four hours trying to figure out why my jQuery events
As far as I understand, binding to a var in ActionScript is carried out
I am working with a WinForm application that was designed by the previous, now

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.