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
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post

    Ajax Simple Request :/

    All I need to do at the moment is get the contents of a file from the server and display it in a div. Need to further develop it when this works though.

    But for some reason this function is not receiving the txt file which is in the same directory as the script :/

    Code:
    function getHTTPObject() {
    	var http = false;
    	if (window.XMLHttpxmlhttp) { 
    		http = new XMLHttpxmlhttp();
    	} else if (window.ActiveXObject) {
    		http = new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	return http;
    }
    function testing() {
    	var xmlhttp = "";
    	xmlhttp = getHTTPObject();
    	xmlhttp.onreadystatechange = function() {
    		if (xmlhttp.readyState == 4) {
    			if (xmlhttp == 200) {
    				document.getElementById('testing_ajax').innerHTML = xmlhttp.responseText;
    			}
    		}
    	};
    	xmlhttp.open("GET", "txt.txt", true);
    	xmlhttp.send();
    }

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Quote Originally Posted by martynball View Post
    All I need to do at the moment is get the contents of a file from the server and display it in a div. Need to further develop it when this works though.

    But for some reason this function is not receiving the txt file which is in the same directory as the script :/

    Code:
    function getHTTPObject() {
    	var http = false;
    	if (window.XMLHttpxmlhttp) { 
    		http = new XMLHttpxmlhttp();
    	} else if (window.ActiveXObject) {
    		http = new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	return http;
    }
    function testing() {
    	var xmlhttp = "";
    	xmlhttp = getHTTPObject();
    	xmlhttp.onreadystatechange = function() {
    		if (xmlhttp.readyState == 4) {
    			if (xmlhttp == 200) {
    				document.getElementById('testing_ajax').innerHTML = xmlhttp.responseText;
    			}
    		}
    	};
    	xmlhttp.open("GET", "txt.txt", true);
    	xmlhttp.send();
    }
    I believe these should be "XMLHttpRequest" rather than "XMLHttpxmlhttp" to make this work.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • Users who have thanked Rowsdower! for this post:

    martynball (07-21-2010)


  •  

    Posting Permissions

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