break

Simple AJAX call

*Note this is really just a test post to test out the code plugin, i’ll update this post to be a little more useful when i get a chance, the function works fine, its just a little hard to follow*

Put the following function into the head of the document

function getQuery(query){
	var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = 'page.php?query='; //This is the path to the file we just finished making *
    	xmlhttp.open('GET', file + query, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    	xmlhttp.onreadystatechange=function() {
        	if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                	var content = xmlhttp.responseText; //The content data which has been retrieved ***
                	if( content ){ //Make sure there is something in the content variable
                     		document.getElementById('stageAjax').innerHTML =  content; //Change the inner content of your div to the newly retrieved content ****
                	}
        	}
	}
        xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}

then create a php page called page.php
Use the query as your $_GET["query"] to return information from the database

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.