?
Solved

Javascript Error: Reference to undefined variable: No such variable 'XMLHttpRequest'

Posted on 2006-11-16
3
Medium Priority
?
794 Views
Last Modified: 2008-02-01
In Opera 7.23 I'm getting the following error on my Ajax code:

message: Reference to undefined variable: No such variable 'XMLHttpRequest'

My create XMLHttpRequest code:

function createRequestObject()
{
    var request_o; //declare the variable to hold the object.
    var browser = navigator.appName; //find the browser name
    if (browser == "Microsoft Internet Explorer")
       {
         /* Create the object using MSIE's method */
         request_o = new ActiveXObject("Microsoft.XMLHTTP");
       }
    else
       {
         /* Create the object using other browser's method */
         request_o = new XMLHttpRequest();
       }
    return request_o; //return the object
}

var http = createRequestObject();

Can anyone explain why I'm getting this JS error?
0
Comment
Question by:rfresh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 41

Accepted Solution

by:
HonorGod earned 500 total points
ID: 17956766
 var xmlHttp;

  //------------------------------------------------------------------
  // Name: createXMLHttpRequest()
  // Role: Create the XML Request Object used by the Ajax routines
  //------------------------------------------------------------------
  function createXMLHttpRequest() {
    if ( window.ActiveXObject ) {
      xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
    } else if ( window.XMLHttpRequest ) {
      xmlHttp = new XMLHttpRequest();
    }
  }
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 17956794
Your if test is failing...

if (browser == "Microsoft Internet Explorer")

0
 
LVL 41

Expert Comment

by:HonorGod
ID: 17961912
Thanks for the 'A'
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question