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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:57:13+00:00 2026-05-25T01:57:13+00:00

I have a script called at the end of an html page like this.

  • 0

I have a script called at the end of an html page like this.

<body>

<script type="text/javascript">

 $(document).ready(function() {
               //define php info and make ajax call to recreate divs from XML data
               $.ajax({
                   url: "get_nodes.php",
                   type: "POST",
                   data: { },
                   cache: false,
                   success: function (response) {

                       if (response != '') 
                       {
                          alert(response);

                       }
                   }
               });
 });

</script>

</body>

The php script has echo statements that write javascript. The echo statements are not printed in the document. They are being sent somewhere, I don’t know where. If I look at the response from the ajax call to php with the alert function, all the echo statements are printed in the alert box as I would expect them to be printed in the document itself.

My questions are:

  • What does ajax do with the php echo statements?
  • What is the way to have them printed in the document?

Here is the PHP file get_nodes.php called through ajax.

<?php

function get_nodes() {
// load SimpleXML
$nodes = new SimpleXMLElement('communities.xml', null, true);

foreach($nodes as $node) // loop through 
{

        echo "\n<script type='text/javascript'>\n";

        echo "  var newdiv = document.createElement('div');\n";
        echo "  newdiv.id = '".$node['ID']."';\n";
        echo "  newdiv.className ='comdiv ui-widget-content';\n";
        echo "  newdiv.style.top = '".$node->TOP."'\n";
        echo "  newdiv.style.left = '".$node->LEFT."';\n";
        echo "  newdiv.style.width = '".$node->WIDTH."';\n";
        echo "  newdiv.style.height = '".$node->HEIGHT."';\n";
        echo "  $( '#page' ).append(newdiv);\n";
        echo "  var heading = document.createElement('p');\n";
        echo "  heading.innerHTML = '".$node->NAME."';\n";
        echo "  heading.className ='comhdr editableText ui-widget-header';\n";
        echo "  $('#".$node['ID']."').append(heading);\n";
        echo "  $('#".$node['ID']."').resizable();";
        echo "  $('#".$node['ID']."').draggable();";
        echo "  $('#".$node['ID']."').draggable('option', 'handle', '.comhdr');";

        printf('$("#%s").append("<a href=\\"#\\" onClick=\\"delete_div(\'%s\');\\">Delete</a>&nbsp;&nbsp;");', $node

['ID'], $node['ID']);

        printf('$("#%s").append("<a href=\\"#\\" onClick=\\"add_url(\'%s\');\\">Add URL</a>&nbsp;&nbsp;");', $node

['ID'], $node['ID']);

        echo "\n</script>\n"; 
}

   return;
}

echo get_nodes();

?>
  • 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-25T01:57:14+00:00Added an answer on May 25, 2026 at 1:57 am

    As Incognito pointed out, your ajax call does not care about what your PHP function is doing – all that matters in this case is the content returned from the server, not how the content is created.

    Try adding the dataType option to your ajax call to specify a response type of script, and use the append or appendTo function to add the script to the document body:

    $.ajax({
        url: "get_nodes.php",
        type: "POST",
        data: { },
        dataType: 'script',
        cache: false,
        success: function (response) {
            if (response != '') 
            {
                $(document.body).append(response);
            }
        }
    });
    

    Also, a suggestion: In your server-side function, why not echo HTML markup instead of a javascript function which creates markup?

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

Sidebar

Related Questions

I have a java script function that i have called on body load mousemove()
I'm creating a Shell Script, and I have a file like this called expressions.txt
I have a Perl script called replaceUp: #!/usr/bin/perl search=$1 replace=$2 find . -type f
Let's say I have a Bash script called foo.sh . I'd like to call
I have a script in Bash called Script.sh that needs to know its own
Suppose I have a python script called my_parallel_script.py that involves using multiprocessing to parallelize
I have a script which, each time is called, gets the first line of
I have a utility build script that gets called from a variety of project-specific
I'm using Firefox 3.6.6. I have a PHP script called index.php with the following
I have a script that calls a php page via jquery/ajax. The results would

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.