Ajax Javascript method cannot be called
- by blackmage
I made this method to load javascript functions dynamically. It does include the .js file but when I call a method, the method says that it is undefinited. The following to .js files are ajax_object.js and user_manager.js . The alert outside the function is read and works but the alert inside does not.
enter code here
//ajax_object.js
//Load a javascript library
function loadJavascript( src, url ){
XMLHttpRequestObject=getXmlHttpRequestObject();
if( XMLHttpRequestObject){
XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 ){
if (XMLHttpRequestObject.status == 200 || XMLHttpRequestObject.status == 304) {
includeJavaScript( src, url, XMLHttpRequestObject.responseText );
}
}
}
}
XMLHttpRequestObject.open('GET', url, true);
XMLHttpRequestObject.send(null);
}//end LoadJavaScript
//Add Library to header
function includeJavaScript(src, fileUrl, xmlObject) {
if ( ( xmlObject != null ) && ( !document.getElementById( src ) ) ){
var documentHead = document.getElementsByTagName('HEAD').item(0);
var includeScript = document.createElement( "script" );
includeScript.language = "javascript";
includeScript.type = "text/javascript";
//includeScript.id = src;
includeScript.src=fileUrl.concat(src);
includeScript.defer = true;
includeScript.text = xmlObject;
documentHead.appendChild( includeScript );
}
}
//user_manager.js
//First alert is read
alert("Outside User Manager");
function selectUserManagerModuleType(){
XMLHttpRequestObject=getXmlHttpRequestObject();
//This doesn't work
//throws selectUserManagerModuleType undefined
alert("Inside The User Manager");
}