View Single Post
Old 06-07-2009, 04:08 PM   #8 (permalink)
jcorradino
The Contributor
 
jcorradino's Avatar
 
Join Date: Sep 2008
Posts: 36
Thanks: 2
jcorradino is on a distinguished road
Default

HTML Code:
<script type="text/javascript" charset="utf-8">
  var response=null;
	//This is to be the data you are passing through the AJAX call, replace "your passed data"
  var param="your passed data"
	//This function will actually make the AJAX call
  function ajaxRequest(param) {
    var request = false;
	//Checks to see if a request can be made (non MS browser)
    if (window.XMLHttpRequest) {
      request = new XMLHttpRequest();
      if (request.overrideMimeType) {
        request.overrideMimeType('text/xml');
      }
	//Checks to see if a request can be made (MS browser)
    } else if (window.ActiveXObject) {
      try {request = new ActiveXObject("Msxml2.XMLHTTP");} 
      catch (e) {
        try {request = new ActiveXObject("Microsoft.XMLHTTP");} 
        catch (e) {}
      }
    }
	//Checks to see if the request from above was able to be made, if not, will display error
    if (!request) {
      alert('There was an error in creating an XMLHTTP instance, please update your browser!');
      return false;
    } else {
	  //Checks to see if there is any returned status
      request.onreadystatechange = function() { statusCheck(request); };
	  //Opens a connection with another page, using (in this case): Post instead of Get, the page yourProcessingPage.php, and false meaning it will stall the function to wait for the response, true rarely works
      request.open('POST', 'yourProcessingPage.php', false);
      request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        request.setRequestHeader("Content-length", param.length);
        request.setRequestHeader("Connection", "close");
		//Sends data
        request.send(param);
    }
  }
  //checks the status of the request
  function statusCheck(request) {
	//Check if the request is complete
    if (request.readyState == 4) {
	  //HTTP status of 200 means ok (500 means server error and 404 means page not found)
      if (request.status == 200) {
		//Sets response text to javascript variable window.response
        window.response=request.responseText;
	  //something fubared, displays error
      } else {
        alert('There was a problem with the request.');
      }
    }
  }
</script>
hope this helped :)
__________________
Jason Corradino
Applications Developer, Interactive Support - Tribune Technology
J2EE Development, Script Tinkering - Develop, Support, and Maintain Tribune websites.
jcorradino is offline  
Reply With Quote