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

  • SEARCH
  • Home
  • 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 7165415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:14:08+00:00 2026-05-28T14:14:08+00:00

I’ve created two simple testpages. One loads the other one using XMLHttpRequest. (just a

  • 0

I’ve created two simple testpages. One loads the other one using XMLHttpRequest. (just a page using slimbox to display a image)
This works perfect the first time. But when trying to run it again, by pressing the button again, it does not work anymore. When I reload the whole page, it works the first time again. Do I have to un-load or re-load the scripts or something?
I know It is double of the script-tags here, don’t know why but its the only way I got it to work in the first place. How come it only works the first time?

Please help.

testajax.php

<html>
<head>
<link rel="stylesheet" href="SlimBox/css/slimbox.css" type="text/css" media="screen"   />


<script id="script1" type="text/JavaScript"></script>
<script id="script2" type="text/JavaScript"></script>
<script type="text/javascript" src="SlimBox/js/mootools.js"></script>  
<script type="text/javascript" src="SlimBox/js/slimbox.js"></script>  

<script type="text/javascript">
function loadXMLDoc(Page)
{
 var xmlhttp;
 if (window.XMLHttpRequest)
 {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
 }
 else
 {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
 xmlhttp.onreadystatechange=function()
 {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
   document.getElementById("myDivFull").innerHTML=xmlhttp.responseText;
   document.getElementById('script1').src = 'SlimBox/js/mootools.js';
   document.getElementById('script2').src = 'SlimBox/js/slimbox.js';
  }
 }
 xmlhttp.open("GET",Page,true);
 xmlhttp.send();
}
</script>
</head>
<body>
  <input id="Header2" type="button" onClick="loadXMLDoc('testImage.php')" name='Sok' value='Load' >            
   <div id="myDivFull"></div> 
</body>
</html>

testImage.php

<a href='img/facebook-icon.png' rel='lightbox' cap='test'><img alt='' border='0' src='img/facebook-icon.png' /></a>

EDIT:
The method provided by gilly3 worked perfectly with the seperate js file, however I can not get it to work if I add a google gadget script ‘link’ into the function. Is this solved in a different way maybe? Below is the code I can not get to work.

function addScript(src)
{
    var script = document.body.appendChild(document.createElement("script"));
    script.src = src;
} 

if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
    document.getElementById("myDivFull").innerHTML=xmlhttp.responseText;
    addScript('//www.gmodules.com/ig/ifr?url=http://www.mortgage-info.com/gadgets    
    /gadgetsmortgagecalculator.xml&amp;synd=open&amp;w=250&amp;h=200& 
    amp;title=Mortgage+Calculator&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&
    amp;output=js');
}

Thank you.

  • 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-05-28T14:14:08+00:00Added an answer on May 28, 2026 at 2:14 pm

    Surely there’s a better way to accomplish what you are trying to do. But, I don’t know what you are trying to do, and there is a simple answer to your question:

    Don’t bother with creating the empty script tags. Just add as many script tags as you like dynamically:

    function addScript(src)
    {
        var script = document.body.appendChild(document.createElement("script"));
        script.src = src;
    }
    
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        document.getElementById("myDivFull").innerHTML=xmlhttp.responseText;
        addScript('SlimBox/js/mootools.js');
        addScript('SlimBox/js/slimbox.js');
    }
    

    Edit: The “better way” would be to create a function that does what you want, and call it whenever you need to. Eg, if your script contained:

    someArray = window.someArray || [];
    var elements = document.querySelectorAll(".someClass");
    for (var i = 0; i < elements.length; i++)
    {
        someArray.push(elements[i].value);
    }
    

    You would just create a function:

    var someArray = [];
    function reInit()
    {
        var elements = document.querySelectorAll(".someClass");
        for (var i = 0; i < elements.length; i++)
        {
            someArray.push(elements[i].value);
        }
    }
    

    Then call it each time you receive your AJAX data.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.