Jump to content

javascript and ajax


dreamwest

Recommended Posts

So ive called a page with ajax but the called page's javascript doesnt work, what am i missing??

 

main.html

<script>
function Data($Request, $Control, $jump, $player) {

	if($jump){
	window.location = String(window.location).replace(/\#.*$/, "") + "#top";
	}
	if($player){
	document.getElementById("more").style.display = "block";
	}
	if ($Control == "" || $Control == null)	{alert ("No output specified !"); return;}
	var ai = new AJAXInteraction($Request, GetServerData,  $Control );
	ai.doGet();
}


function GetServerData  ($TheData, $Control){
	document.getElementById($Control).innerHTML = $TheData;
}

function AJAXInteraction(url, callback, $Control) {
   	var req = init();
    req.onreadystatechange = processRequest;
        
    	function init() {
		if	(window.XMLHttpRequest)		{	return new XMLHttpRequest();					} 
		else if (window.ActiveXObject)	{	return new ActiveXObject("Microsoft.XMLHTTP");  }
		else {alert ("Your browser seems to be out of date, Please update!"); return;		}
    }
    
    	function processRequest () {
		if (req.readyState == 4) {
	        if (req.status == 200) callback(req.responseText, $Control);
		}
		else	callback(Myvar , $Control);
    }
	this.doGet = function() {
      req.open("GET", url, true);
    	  req.send(null);
    }
    
    
   }
</script>

<span onclick='Data("/page.html", "T"); return false;'>Click</span>

<ul id='T'></ul>

 

 

page.html

<script src='/jquery_tools.js'></script>
..javascript stuff here

Link to comment
https://forums.phpfreaks.com/topic/223848-javascript-and-ajax/
Share on other sites

Ok this i everthing relevant

 

ajax.js

	function Data($Request, $Control, $jump, $player) {

	if($jump){
	window.location = String(window.location).replace(/\#.*$/, "") + "#top";
	}
	if($player){
	document.getElementById("more").style.display = "block";
	}
	if ($Control == "" || $Control == null)	{alert ("No output specified !"); return;}
	var ai = new AJAXInteraction($Request, GetServerData,  $Control );
	ai.doGet();
}


function GetServerData  ($TheData, $Control){
	document.getElementById($Control).innerHTML = $TheData;
}

function AJAXInteraction(url, callback, $Control) {
   	var req = init();
    req.onreadystatechange = processRequest;
        
    	function init() {
		if	(window.XMLHttpRequest)		{	return new XMLHttpRequest();					} 
		else if (window.ActiveXObject)	{	return new ActiveXObject("Microsoft.XMLHTTP");  }
		else {alert ("Your browser seems to be out of date, Please update!"); return;		}
    }
    
    	function processRequest () {
		if (req.readyState == 4) {
	        if (req.status == 200) callback(req.responseText, $Control);
		}
		else	callback(Myvar , $Control);
    }
	this.doGet = function() {
      req.open("GET", url, true);
    	  req.send(null);
    }
    
    
   }

 

 

main.html

<script src="/ajax.js"></script>
<span onclick='Data("/page.html", "T"); return false;'>Click</span>
<ul id='T'></ul>

 

 

page.html

<script src="/ajax.js"></script>
<span onclick='Data("/test.html", "T"); return false;'>Click</span>

 

test.html

page.html has initiated this page

 

So the javascrpt in page.html isnt getting initiated

Link to comment
https://forums.phpfreaks.com/topic/223848-javascript-and-ajax/#findComment-1157196
Share on other sites

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.