SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    function is not defined

    hi there ,
    I am trying the following code on firefox 2.0 and the javasctipt error console is saying "makerequest is undefined".
    Can someone pls tell me whats wrong with it ?

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Trasnsitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Welcome me </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text\javascript" >
    var xmlhttp= false; 
    	//check if we are using IE 
    	try
    	{
    	//if the javascript version is greater than 5 
    	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    	alert ("You are using M$IE.");
    	}
    	catch (e)
    	{ 
    	//if not, then use the older active x object 
    		try
    		{
    		//if we are using M$IE. 
    		xmlhttp=new ActiveXobject("Microsoft.XMLHTTP");
    		alert ("You are using M$IE."); 
    		}
    	
    		catch (E) 
    		{
    		//else we are using a non-IE browser 
    		xmlhttp=false;
    		}
    	} 
    //if we are using a non-IE browser, create a javascript instance of the object.
    	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
    	{ 
    	xmlhttp=new XMLHttpRequest(); 
    	alert("You are using a not M$IE");
    	}
    	function makerequest(serverPage, objID)
    	{ 
    	var obj=document.getElementById(objID); 
    	xmlhttp.open("GET",serverPage,true); 
    	xmlhttp.onreadystatechange=function()
    		{
    		if(xmlhttp.readyState==4 && xmlhttp.status == 200)
    			{
    				obj.innerHTML = xmlhttp.responseText; 
    			}
    
    		}
    	xmlhttp.send(null);
    	}
    
    </script>
    </head>
    <body onload="makerequest('page1.php','hw')">
    <div align="center">
    <h1>My Webpage</h1> 
    <a href="page1.php" onclick="makerequest('page1.php','hw'); return false;">Page 1</a> | 
    <a href="page2.php" onclick="makerequest('page2.php','hw'); return false;">Page 2</a> | 
    <a href="page3.php" onclick="makerequest('page3.php','hw'); return false;">Page 3</a> 
    <div id="hw">Hello</div>
    </div>
    </body>
    </html>
    
    </body>
    </html>
    cya

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe it's because of the incorrect type value in your <script> tag. MIME types and subtypes are separated by a forward slash, not a backslash:
    Code:
    <script type="text/javascript">
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh my, and the expressions
    Code:
    //check if we are using IE 
    	try
    	{
    	//if the javascript version is greater than 5 
    	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    	alert ("You are using M$IE.");
    	}
    	catch (e)
    	{ 
    	//if not, then use the older active x object 
    		try
    		{
    		//if we are using M$IE. 
    		xmlhttp=new ActiveXobject("Microsoft.XMLHTTP");
    		alert ("You are using M$IE."); 
    		}
    	
    		catch (E) 
    		{
    		//else we are using a non-IE browser 
    		xmlhttp=false;
    		}
    	}
    are making firefox freeze .

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,870
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    There is nothing in your posted code that any browser except IE would understand.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IE now supports XMLHttpRequest, so a good check would be something like:

    Code JavaScript:
    if(window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
    }
    else if(......


    And yes, the backslash in "text\javascript" definitely generates an error. Try Firebug! If you paste your first piece of code (of course, without the <script> tag), you'll see it works fine.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •