SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,760
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need Help w/Quick AJAX Adjustment (do something if activex na)

    I have this function for my AJAX:

    Code:
    function firstcheck() {
    dtext = "";
    		if (window.XMLHttpRequest)
      		{
      		xmlhttp=new XMLHttpRequest();
      		}
    		else
      		{
      		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      		}
    			xmlhttp.onreadystatechange=function()
      			{
      			if (xmlhttp.readyState==4 && xmlhttp.status==200)
        		{
        		dtext = xmlhttp.responseText;
        		}
      			}
    xmlhttp.open("POST","/file.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    var tkey = "";
    xmlhttp.send("tid="+ tkey +"");
    }
    Now, I want to add a bit of code that does something if ACTIVEX is not available or if the browser can't support AJAX. How can I edit this to allow for that?

    Cheers!
    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just add an if statement within you else statement to check whether xmlhttp is null or not. If so do something...

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For better well tested API I would recommend you to use jQuery AJAX which is pretty easier to implement.
    http://docs.jquery.com/Ajax/jQuery.p...tacallbacktype
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,760
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying to avoid jquery just to limit the size, but would I just do...

    Code:
    if(!xmlhttp) {
    //no activex spotted
    }
    or should I just have an if statement before everything like:

    Code:
    if (!window.XMLHttpRequest && !ActiveXObject("Microsoft.XMLHTTP")) {
    //no way for AJAX, so do this
    } else {
    //run rest of statement
    }
    Would that work?

    Thanks
    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can just do:

    if(ActiveXObject) {
    alert("yay we have activeX support");
    }
    else {
    alert("nope, no activeX");
    }


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
  •