Solved

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

Posted on 2006-11-16
3
782 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 125 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…
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…

726 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