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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:30:25+00:00 2026-06-02T04:30:25+00:00

Currently, I have a Javascript file (running on the client) that I call a

  • 0

Currently, I have a Javascript file (running on the client) that I call a PHP file(on the server) from. After the PHP file finishes, I would like to pass three variables back to the javascript that is running on the client. I figured out how to make the javascript wait for the php file for finish executing, so that is not the problem. The problem is passing the variables back to the javascript file. Can this be done? All the examples that I have seen have has some sort of hybrid javascript/php file. I was hoping to find some way to pass the php variables kind of like the jquery.ajax does. I don’t know if this can be done because I am so new to Javascript and PHP.
Thanks,

javascript:

<html>
    <head>
        <title>Login Page</title>
    </head>
    <script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
    <script language="Javascript">
        function calculations(callback)
        {
            var x = <?php echo $username?>;
            alert(x);
            var password = window.prompt("Please Type Your Password");
        }//ends the calculations function
        function getUsername()
        {
            var username = window.prompt('Please Type Your Username');
            var temp = document.getElementById('temp');
            temp.innerHTML = username;
            jQuery.ajax(
                {
                    type: "POST",
                    url:"GetInfo.php",
                    data: "username="+username,
                    success: function(msg)
                            {callback.call();}

                });//ends the jQuery send


        }//ends the GetUsername function
    </script>
    <body onLoad=getUsername()>
        <div id="temp">This will show text</div>

    <body>

</html>

php:

<?
//$username = $_POST['username'];
$username = "tom";
$inFile="MyID.config.php";
$handle=fopen($inFile, 'r') or die ("No credentials could be gotten because the file MyID.config.php would not open.");
$data='0';

do{
$data = fgets($handle);
$temp = substr($data,0, 10);
//echo $temp.strcmp($temp,'\'username\'')."\n";
}while (strcmp($temp, '\'username\'')!= 0);


$data = substr($data,15,strlen($username));

if (strcmp($data, $username == 0) )
{
    $read_in = fgets($handle);
    $x = substr($read_in,8,-3);
    $read_in = fgets($handle);
    $y = substr($read_in,8,-3);
    $read_in = fgets($handle);
    $salt = substr($read_in,11,-3);
}//ends the strcmp $data and $username if statement.
fclose($handle);

?>
  • 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-02T04:30:27+00:00Added an answer on June 2, 2026 at 4:30 am

    To pass data back to the Javascript that called the script, just echo like this:

    $value = 'foobar';
    echo $value;
    

    For multiple values, you could pass it back as a JSOn object

    $name = 'foobar';
    $text = 'helloworld';
    $value = 5;
    
    //add to associative array
    
    $result['name'] = $name;
    $result['text'] = $text;
    $result['value'] = $value;
    
    // encode as json and echo
    echo json_encode($result);
    

    On the Javascript side, your callback function would receive this:

    function callback(data){
        var result = JSON.parse(data);
        //access the members
        console.log(result.name);
        console.log(result.text);
        console.log(result.value);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a Javascript function that uses a string to reference an object
I am currently trying to pass an array that I have created in Javascript
I am currently using the JQuery ajax function to call an exterior PHP file,
I have a javascript file linked to a PHP page which has a value
I have a mov file that's 157 megabytes. I try running it on my
I have a little bit of Javascript that almost works correctly. Here's the code:
I have a facebook app using a lot of Javascript that doesn't work correctly
Currently have password protection on my main and sub directories, however I'd like to
I currently have a Gridview , And I want to use client-side validation to
I currently have a need for a custom ListViewItem class - let's call it

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.