Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    CPW
    CPW is offline
    Member
    Join Date
    Sep 2006
    Posts
    53
    Member #
    13935
    Hello,

    I'm designing my first site in AJAX right now. I don't want to have to have lots of copies of the code to create the request object. You know, where you use try... catch to set the right kind of object depending on the variable. So I wrote a function that returns a new object of the correct type. It looks like this:
    Code:
    function ajax_create() {
    	try {
    		return(new XMLHttpRequest());
    	}
    	catch(e) {
    		try	{
    			return(new ActiveXObject('Msxml2.XMLHTTP'));
    		}
    		catch(e) {
    			try {
    				return(new ActiveXObject('Microsoft.XMLHTTP'));	
    			}
    			catch(e) {
    			}
    		}
    	}
    }
    Then anytime I want to create a request object, I just do this:
    Code:
    var ajax = ajax_create();
    This works fine in Opera and Firefox. But in IE, there is a JavaScript error that says an object is expected. I've searched all over the internet about passing references instead of values and all of that, but so far nothing has worked. It doesn't seem like it should be difficult to do this. So maybe I'm missing something.

    Thanks for the help.

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    I recreated the page and tested it in IE7 and the code did not fail, is it IE7 you are having trouble with?

    Can you provide us with a sample page that fails?

  4. #3
    CPW
    CPW is offline
    Member
    Join Date
    Sep 2006
    Posts
    53
    Member #
    13935
    Sorry for taking so long to respond. I solved the problem. Well, not quite, but I realized that that isn't the problem. You are right, that code works fine. But I had the function and the code calling the function in two different files, and apparently it was causing problems in IE. If I put them in the same file it works fine. Thanks for the help, though. :-)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:25 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com