Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8984081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:00:12+00:00 2026-06-15T21:00:12+00:00

I am currently contracted to a place that cannot use a CMS or PHP,

  • 0

I am currently contracted to a place that cannot use a CMS or PHP, but they want me to build something like a CMS using HTML and JavaScript.

I know it sounds ridiculous but I do not want to be searching for another job these days and they are the nicest people that I have ever worked for – EVER – and I old.

One of the concepts of a CMS is to have global files that you can include at any given time.

As a result, I tried the $.ajax, $.get, etc…, but I was running into issues of Access URI denied and those kind of things for trying to load a file which is one directory level the current directory.

I was able to get the javascript file to load by using the old XMLHttpRequest/ActiveXObject.

However, the script within the div that has been loaded cannot be called. I receive an error of “Can’t find variable: mFunc” which is the name of the function that has been loaded into the div.

Here’s the code for my html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>retrieve local file one level up</title>
<script type="text/javascript">
<!--
var createRequestObject = function(){   
    var req;

    if(window.XMLHttpRequest){
        // Firefox, Safari, Opera...
        req = new XMLHttpRequest();
    }else if(window.ActiveXObject){
        // Internet Explorer 5+
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        alert('There was a problem creating the XMLHttpRequest object');
    }   
    return req; 
}

    // Make the XMLHttpRequest object
    var http = createRequestObject();


var sendRequestPost = function(){
    var jscript = '../test.js';
    // Open PHP script for requests
    http.open('GET', jscript);
    http.setRequestHeader('Content-Type', 'text/javascript');
    http.onreadystatechange = handleResponsePost;
    http.send(null);
    var mT = setTimeout("mFunc()", 2000);
}

var handleResponsePost = function(){
    if(http.readyState == 1){
        document.getElementById('mDiv').innerHTML = "Please wait, loading... " ; 
    }else if(http.readyState == 4 && http.status == 200){
        // Text returned from PHP script
        var response = http.responseText;
        document.getElementById('mDiv').innerHTML = response;

        if(response){
            // Update ajaxTest2 content
            document.getElementById('mDiv').innerHTML = response;
        }
    }else if(http.readyState == 2){
        document.getElementById('mDiv').innerHTML = http.responseText;
    }else if(http.readyState == 3){
        document.getElementById('mDiv').innerHTML = http.responseText;
    }
}
-->
</script>
</head>

<body onload="javascript:sendRequestPost();">
<div id="mDiv"></div>
</body>
</html>

Here is the javascript that loads just fine into mDiv:

<script type="text/javascript">
<!--
var mFunc = function(){
    var mScript = document.createElement("script");
    mScript.setAttribute("type","text/javascript");
    var data = 'alert("gets here");'
    mScript.text = data;

    var head = document.getElementsByTagName("head")[0];
    head.appendChild(mScript);
}
-->
</script>

Yet, after the two seconds have passed, I receive the error.

I am sure that it is probably because the browser just sees this as text within the div, so how do I make it recognize that it is javascript.

I have tried using eval, which I do not want to use, but even returns a parse error.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:00:14+00:00Added an answer on June 15, 2026 at 9:00 pm

    OK, another programmer that I work with, has found a simple solution.

    Instead trying to use ajax to load a JavaScript file from a higher directory level and then run a document.writeln or document.getElementById(“someDiv”).innerHTML — reverse the steps.

    Include the JS file as you would normally:

    <script type="text/javascript" src="../../common/header.js"></script>
    

    Within this JS file

    function CommonHeader(mPath) {
        document.writeln('<header>');
        document.writeln('  <div class="PageWidth">');
        document.writeln('      <h1><a href="' + mPath + 'index.html"     title="Something">Something<sup>&reg;</sup></a> <a  href="http://www.xyz.com/abc.html" title="Learn more about us."><em>Learn about us</em></a></h1>');
        document.writeln('      <nav>');
        document.writeln('          <ul>');
        document.writeln('              <li id="loginOut"></li>');
    

    The order needs to be for you to call document.writeln at the beginning of the process.

    We can now load header.js, footer.js, and whatever other file that we wish to load, along with having an array at the top of each page denoting the path to those files, for lower directory level htmls

    dynamicPathArr[0] = "../../";
    

    Then within whatever file, you can call the function to write the date into the page

    <script type="text/javascript">CommonHeader(dynamicPathArr[0])</script>
    

    I cannot believe that I did not think of this completely simple solution.

    Although this is not SEO friendly, it is good for only updating header, footer, nav, etc… in one location, until everything is finalized.

    And thanks you for the response

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently we use log4net of version 1.2.10.0 and we should start using some 3rd
Currently, I am writing a MiddleWare application that synchronizes information between and accounting application
Currently I am using HTML files for parts of my user interface. I display
currently, I`m implementing a map App with Mono4Droid and there I`m using a WebView
Currently working with converting SQLException error messages into messages that are more useful for
Currently I have this code: <?php echo '<meta name=robots content=noindex>'; $arr = json_decode(file_get_contents(http://media1.clubpenguin.com/play/en/web_service/game_configs/ paper_items.json),true);
I am currently trying to create a system in which I want to be
I am currently working on an application that pulls Google Map locations from an
What I want to do is run a method that will play a random
I have a method that currently returns a string converted from a byte array:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.