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 7585585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:12:42+00:00 2026-05-30T19:12:42+00:00

Suppose I have this code: my_script_data = document.getElementById(id_php_defer__core); if (my_script_data == undefined) { Alert(request.responseText);

  • 0

Suppose I have this code:

my_script_data = document.getElementById("id_php_defer__core");
if (my_script_data == undefined) {
  Alert(request.responseText); // all looks good!
  my_script_data = document.createElement("script");
  my_script_data.setAttribute("id", "id_php_defer__core");
  my_script_data.innerHTML = 'function myinitfunc() { ' + "\n" + request.responseText + "\n" + ' }';
  to = document.head;
  if (to != undefined) {
    to.appendChild(my_script_data);
  }
}
else {
  Alert(request.responseText); // all looks good!
  my_script_data.innerHTML = 'function myinitfunc() { ' + "\n" + request.responseText + "\n" + ' }';
  eval(my_script_data.innerHTML);
}

The “request.responseText” is actually a Javascript array declaration with lots of values set.

After above code, the “myinitfunc” is called later.

(And as it should only contain “request.responseText” the global (!) array of values should be updated.)

However, while the code works on first run, subsequent runs seem to do nothing, so I am doing something wrong, but what? 🙂

  • 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-30T19:12:44+00:00Added an answer on May 30, 2026 at 7:12 pm

    <script> tags cannot be recycled. To fix that, you decided to use eval.

    However (certainly in strict mode), eval does not run in the current nor global scope. As a result, the declared function does not show up.

    I strongly discourage using eval for this purpose. You said that responseText contains an array. By tweaking a bit, you can use JSON to handle data.

    You can also insert and remove a script element in the following way:

    var s = document.createElement('script');
    s.appendChild(document.createTextNode(request.responseText));
    // ^ Equivalent to a "global eval"
    (document.head || document.getElementsByTagName('head')[0]).appendChild(s);
    s.parentNode.removeChild(s);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this (C++ or maybe C) code: vector<int> my_vector; for (int i
Suppose I have this code: var myArray = new Object(); myArray["firstname"] = "Bob"; myArray["lastname"]
Suppose I have this code: String encoding = UTF-16; String text = [Hello StackOverflow];
Suppose I have code like this: template<class T, T initial_t> class Bar { //
Suppose to have a code like this: <div class=notSelected> <label>Name <input type=text name=name id=name
Suppose, I have a connected socket after writing this code.. if ((sd = accept(socket_d,
Suppose, I have saved some permissions in the database by using this code: RoleRepository
I've seen second one in another's code and I suppose this length comparison have
Suppose I have 1) a HTML document. 2) This HTML document loads Javascript file
Suppose I have this Windows wchar_t string: L\x4f60\x597d and L\x00e4\x00a0\x597d and would like to

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.