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

The Archive Base Latest Questions

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

Had a nice PHP/HTML/JS prototype working on my personal Linode, then tried to throw

  • 0

Had a nice PHP/HTML/JS prototype working on my personal Linode, then tried to throw it into a work machine.

The page adds a script tag dynamically with some JavaScript. It’s a bunch of Google charts that update based on different timeslices. That code looks something like this:

// jQuery $.post to send the beginning and end timestamps
$.post("channel_functions.php", data_to_post, function(data){
   // the data that's returned is the javascript I want to load
   var script = document.createElement('script');
   var head= document.getElementsByTagName('head')[0];
   var script= document.createElement('script');
   var text = document.createTextNode(data);
   script.type= 'text/javascript';
   script.id = 'chart_data';
   script.appendChild(text);
   // Adding script tag to page
   head.appendChild(script);
   // Call the function I know were present in the script tag
   loadTheCharts();
});

function loadTheCharts() {
   // These are the functions that were loaded dynamically
   // By this point the script tag is supposed be loaded, added and eval'd
   function1();
   function2();
}

Function1() and function2() don’t exist until they get added to the dom, but I don’t call loadTheCharts() until after the $.post has run so this doesn’t seem to be a problem.

I’m one of those dirty PHP coders you mother warned you about, so I’m not well versed in JavaScript beyond what I’ve read in the typical go-to O’Reilly books. But this code worked fine on my personal dev server, so I’m wondering why it wouldn’t work on this new machine.

The only difference in setup, from what I can tell, is that the new machine is running on port 8080, so it’s 192.168.blah.blah:8080/index.php instead of nicedomain.com/index.php.

I see the code was indeed added to the dom when I use webmaster tools to “view generated source” but in Firebug I get an error like “function2() is undefined” even though my understanding was that all script tags are eval’ed when added to .

My question: Given what I’ve laid out, and that the machine is running on :8080, is there a reason anyone can think of as to why a dynamically loaded function like function2() would be defined on the Linode and not on the machine running Apache on 8080?

  • 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-14T08:27:09+00:00Added an answer on May 14, 2026 at 8:27 am

    jQuery supports javascript responses:

    $.post("channel_functions.php", data_to_post, 
           function (data, textStatus, xhr) {loadTheCharts()}, 
           'script');
    

    However, a dataType of “script” will turn a cross-domain POST into a GET, as per the documentation.

    The main problem with eval is the eval-ed code inherits the scope the eval is in. Instead, you can use jQuery.globalEval. Try something like:

    $.post("channel_functions.php", data_to_post, 
           function (data, textStatus, xhr) {
               /* data might have errors, which will cause an exception.
                  We'll let the default exception handler catch & log it.
                */
               $.globalEval(data);
               loadTheCharts();
           });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The first one doesn't work because you're overriding the action… May 14, 2026 at 9:35 am
  • Editorial Team
    Editorial Team added an answer The problem seems to be specific to OS X and… May 14, 2026 at 9:35 am
  • Editorial Team
    Editorial Team added an answer Solution below is assuming that status can be represented as… May 14, 2026 at 9:35 am

Related Questions

I am probably making some silly mistake but I am newer to the world
I have a couple search forms, 1 with ~50 fields and the other with
I'm an experienced developer who has been working with .Net for the last 5
I'm trying to improve my web development skills. I'm already familiar enough with HTTP,
I'm running PHP on Windows/IIS. My session variables don't seem to be preserved from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.