Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Objects problem, very confused.

    So, I have a javascript object that inherits from the XMLHttpRequest() object. The problem is, it seems it can access two of the required functions, but not the last one. Any help would be much appreciated.

    Code:
    function start() {
    	display('Start<br>', false, 'content');
    	handlerxml('head', false, 'header.php');
    }
    
    function handlerxml(ID, setapp, page) {
    	this.prototype =  new GetXmlHttpObject();
    	this.outID = ID;
    	display('Calldiv 1<br>', true, 'content');
    	this.app = setapp;
    	display('Calldiv 2<br>', true, 'content');
    	var url=page;
    	display('Calldiv 3<br>', true, 'content');
    	try {
    		this.onreadystatechange=stateChanged;
    		display('Calldiv 4<br>', true, 'content');
    	}
    	catch(err) {
    		display( err + '<br>', true, 'content');
    	}
    	try {
    		this.open("GET",url,true);
    		display('Calldiv 5<br>', true, 'content');
    	}
    	catch(err) {
    		display( err + '<br>', true, 'content');
    	}
    	try {
    		this.send(null);
    		display('Calldiv 6<br>', true, 'content');
    	}
    	catch(err) {
    		display( err + '<br>', true, 'content');
    	}
    }
    
    function stateChanged() { 
    	if (this.readyState==4)
    	{ 
    		display(this.responseText, this.app, this.outID);
    	}
    }
    
    function GetXmlHttpObject()
    {
    	var xmlHttp=null;
    	try
    		{
    		// Firefox, Opera 8.0+, Safari
    		xmlHttp=new XMLHttpRequest();
    		}
    	catch (e)
    	{
    		// Internet Explorer
    		try
    		{
    			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    		}
    		catch (e)
    		{
    			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    		}
    	}		
    	return xmlHttp
    }
    This is the output
    Code:
    Start
    Calldiv 1
    Calldiv 2
    Calldiv 3
    Calldiv 4
    Calldiv 5
    TypeError: Object [object global] has no method 'send''


    Also, to clarify why I need this in object form seeing as how the original code works flawlessly, I have to be able to change the contents of multiple divs at a time, which it just kinda fails at unless you have more than one object doing it.
    Last edited by sythem; 09-10-2008 at 03:47 AM.

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    You are calling handlerxml as a normal function call. That means that this will be the global object, i.e. window. Understanding that, your problem should be glaringly obvious.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

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