JavaScript: Funktion nicht definiert (not defined)

Alt 28.08.2011, 17:26   # 1
thorr
 
Benutzerbild von thorr
 
Registriert seit: 22.11.2008
Beiträge: 40
Ich habe drei JavaScript-Dateien, die ich auf einer Seite einbinde und die miteinander verzahnt sind. Die erste, die eingebunden wird, enthält Ajax-Handler und die Funktion getLanguage. Die dritte regelt eine Speicherabfrage beim Verlassen der Seite und greift auf die getLanguage-Funktion zu. Allerdings zeigt die Fehlerkonsole des Firefox beim Verlassen der Seite die Fehlermeldung "getLanguage is not defined".

Code:
function ajaxRequest(url, options)
{
	this.url = url;
	this.method = (options.method) ? options.method : 'GET';
	this.query = (options.query) ? options.query : null;
	this.func = (options.onComplete) ? options.onComplete : null;
	this.req = (window.XMLHttpRequest)
		? new XMLHttpRequest()
		: ((window.ActiveXObject)
			? new ActiveXObject('Microsoft.XMLHTTP')
			: false);
}

ajaxRequest.prototype.dorequest = function() {
	this.req.open(this.method, this.url, true);
	if (this.method == 'POST')
	{
		this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	}
	
	var this_obj = this;
	var func = this.func;
	
	this.req.onreadystatechange = function() {
		if (this_obj.req.readyState == 4 && this_obj.func != null)
		{
			this_obj.func(this_obj.req.responseText, this_obj.req.responseXML);
		}
	};
	this.req.send(this.query);
};

var language = false;

function getLanguage(var langSet, var lang)
{
	var url = scriptPath + 'language.php?ls=' + langSet + '&l=' + lang;
	
	var http = new ajaxRequest(url, {
			method:'GET',
			onComplete:getLanguage_handler});
	http.dorequest();
	
	if (!language)
	{
		// Return key
	}
	else
	{
		return language;
	}
}

function getLanguage_handler(text, xml)
{
	if (text)
	{
		language = text;
	}
}
(common.js)

Code:
var contentChanged = false;

function setConfirm()
{
	contentChanged = true;
}

function saveConfirm()
{
	var leaveLink = document.getElementById('leavelink').href;
	
	if (contentChanged)
	{
		var language = getLanguage('acp/article', 'CONFIRM_SAVE');
		var confirmed = confirm(language);
		
		if (confirmed)
		{
			window.location = leaveLink;
		}
		else
		{
			return false;
		}
	}
}
(article_functions.js)

HTML-Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<meta name="author" content="" />
	
	<link rel="stylesheet" type="text/css" href="{T_TEMPLATE_PATH}/acp/style.css" media="all" />
	<script type="text/javascritp" src="{T_SCRIPT_PATH}/common.js"></script>
	<script type="text/javascript" src="{T_SCRIPT_PATH}/article_functions.js"></script>
	<script type="text/javascript" src="{T_SCRIPT_PATH}/lock_handling.js"></script>

	<title>{PAGE_TITLE}</title>
</head>

<body <!-- IF S_BODY_ONLOAD --> onload="{S_BODY_ONLOAD}"<!-- ENDIF --><!-- IF S_BODY_ONUNLOAD --> onunload="{S_BODY_ONUNLOAD}"<!-- ENDIF -->>

<span class="inforow">
	<a href="{U_LOGOUT}" class="logout-link">{L_LOGOUT}</a>
</span>

<img src="{T_IMAGE_PATH}/acp_boxtop.jpg" alt="" class="boxtop" />
<div class="boxoverall">

<!-- INCLUDE acp/navigation_body.html -->

<div class="contentbox">

<h1>{SITE_HEADLINE}</h1>
Die einzige Erklärung ist für mich, dass zuvor ein Syntaxfehler in der common.js die Kompilierung abbricht. Allerdings müsste Firefox in dem Fall eine Fehlermeldung ausgeben, oder?
  Mit Zitat antworten
Alt 30.08.2011, 00:52   # 2
thorr
Threadstarter
 
Benutzerbild von thorr
 
Registriert seit: 22.11.2008
Beiträge: 40
Das Problem hat sich erledigt. Der Fehler lag darin, dass ich oben im Header einen Tippfehler beim type drinhabe ("text/javascritp").
  Mit Zitat antworten

Alt 28.05.2012, 21:09 # --
News Flash
 
Benutzerbild von News Flash
 
 
 
   
Antwort
Themen-Optionen



Alle Zeitangaben in WEZ +2. Es ist jetzt 21:09 Uhr.