Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-21-2010, 01:12 PM   PM User | #1
martynball
Regular Coder

 
Join Date: Nov 2007
Posts: 554
Thanks: 231
Thanked 0 Times in 0 Posts
martynball is an unknown quantity at this point
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();
}
martynball is offline   Reply With Quote
Old 07-21-2010, 05:36 PM   PM User | #2
Rowsdower!
Senior Coder

 
Rowsdower!'s Avatar
 
Join Date: Oct 2008
Location: Some say it's everything.
Posts: 2,007
Thanks: 5
Thanked 395 Times in 388 Posts
Rowsdower! has a spectacular aura aboutRowsdower! has a spectacular aura aboutRowsdower! has a spectacular aura about
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
Rowsdower! is offline   Reply With Quote
Users who have thanked Rowsdower! for this post:
martynball (07-21-2010)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:53 AM.


Advertisement
Log in to turn off these ads.