View Single Post
Old 11-16-2008, 04:51 PM   #2 (permalink)
mgwalk
Junior Member
 
Join Date: Nov 2008
Posts: 9
Default Re: How To Automatically Add AJAX Functionality to A Static Web Site

you can use this code to fetch data from txt, htm, php files/pages.

Code:
function get_data()
		{
                var myStr = 'var1=data1&var2=data2&var3=data3'; 
		var myurl = 'your_file_here';
		var xmlhttp=new XMLHttpRequest();
		xmlhttp.onreadystatechange= function() 
			{ 
			if (xmlhttp.readyState==4)
			if (xmlhttp.status==200)
				read_data(xmlhttp);
			}
		xmlhttp.open("POST",myurl,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.send(myStr);
		}

function get_data(req) {
 alert(req.responseText); //this will return your data 
}
mgwalk is offline   Reply With Quote
Sponsored Links