Jump to content

http.opening a page on a different server


newbreed65

Recommended Posts

Hiya everyone

 

I'm currently working on a project where I need to be able to log certain information by Ajax running a php page behind the scene that logs the information in a database. I can get this working fine when both verbiage's are located on one domain server but I'm having difficulty getting it to work when there on separate servers...

 

I'm ab it of a noob when it comes to Ajax and got a feeling I'm trying to wrong thing when your need to interact with different servers, just a lil unsure were to go now

 

Below is the code i have currently

 

function getXMLHTTPRequest() {
			try {
			req = new XMLHttpRequest();
			} catch(err1) {
			  try {
			  req = new ActiveXObject("Msxml2.XMLHTTP");
			  } catch (err2) {
				try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (err3) {
				  req = false;
				} 
			  } 
			}
			return req;
			}

			var http = getXMLHTTPRequest();

			function getServerText() {
			  var myurl = 'http://www.ftp5.dns-systems.net/~guardhog/test.php';
			  myRand = parseInt(Math.random()*999999999999999);
			  
			  var client = "&client=123456"
			  var modurl = myurl+"?rand="+myRand+client;

			  http.open("GET", modurl, true);
			  http.onreadystatechange = useHttpResponse;
			  http.send(null);
			}

			function useHttpResponse() {
			   if (http.readyState == 4) {
				if(http.status == 200) { 
				  var mytext = http.responseText;
				  document.getElementById('myPageElement').innerHTML = mytext;
				}
			  } else {
			  document. getElementById('myPageElement').innerHTML = "";
			  }
			}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.