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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:29:25+00:00 2026-06-15T16:29:25+00:00

Let say I submit data to a form with the following code var xhr

  • 0

Let say I submit data to a form with the following code

var xhr = new XMLHttpRequest(), formData = new FormData();  
formData.append("img", img);
formData.append("user", localStorage["username"]);
formData.append("pass", localStorage["password"]);

xhr.onreadystatechange = function (event) {
    if (xhr.readyState === 4 && xhr.status === 200) {
       var value = xhr.responseText; // value should equal "1234"
        alert( "value = " + value );
    }else{
    alert("none");
}
};
xhr.open("POST", "http://joubin.me/uploads3/upload_file.php", true);
xhr.send(formData);

After upload.php is done, it redirects to another page called giveid.php and the only thing it displays is a text string with an id

say 1234

How can I with javascript capture this exact id.

Keep in mind, a different upload.php redirect will have a different id number on giveid.php?

I looked into the xmlhtml responses and could not figure it out.

Here is what form goes

$password = $_REQUEST['pass'];
$username =  $_REQUEST['user'];
$image = $_REQUEST['img'];
echo $password;
echo "<br/>";
echo $username;
echo "<br/>";
echo $image;
$con = mysql_connect("localhost","ya","right");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
        echo "could not connect";
  }
$asql = "SELECT * FROM `ashkan`.`users` where user='$username' and pass='$password';";

$result = mysql_query($asql);
echo $result;
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

echo $count;

echo 11;
if($count == 1){
$sql = "INSERT INTO `ashkan`.`goog` (`user`, `pass`, `img`) VALUES ('$username', '$passwo$
}
mysql_query($sql);
mysql_close($con);
header( 'Location: giveid.php' ) ;

and here is the content of giveid.php

1234

Any help would be great.

Thanks

  • 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-15T16:29:26+00:00Added an answer on June 15, 2026 at 4:29 pm

    You need to use xhr.onreadystatechange to retrieve the response from the server.

    Something like this might work.

    var value;
    var formData = new FormData();
    formData.append("img", img);
    formData.append("user", localStorage.username);
    formData.append("pass", localStorage.password);
    
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function (event) {
        if (xhr.readyState === 4 && xhr.status === 200) {
            value = xhr.responseText; // value should equal "1234"
            alert( "value = " + value );
        }
    };
    xhr.open("POST", "upload.php", true);
    xhr.send(formData);
    

    Info Here: http://www.tizag.com/ajaxTutorial/ajaxxmlhttprequest.php

    Remember that header() must be called before any actual output is sent. So get rid of all the echos you have in the php file. Once you echo then that starts the output buffer for the response to the client.

    Info Here: http://php.net/manual/pt_BR/function.header.php

    I think this should be your only echo on the php page.

    echo include( 'giveid.php');
    

    Try using Google Chrome Dev Tool Network tab to view the response from your php webpage.

    • Launch Google Chrome,
    • Hit f12,
    • Click the network tab,
    • reload your page,
    • click on the ajax response page,
    • click preview to view the response.

    Info Here: https://developers.google.com/chrome-developer-tools/docs/network

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

Sidebar

Related Questions

Let's say we have this code: <form action='' method='POST' enctype='multipart/form-data'> <input type='file' name='userFile'><br> <input
Let's say I'm at http://www.domain.com/page.html . I want to submit this form: <FORM METHOD=post
Let say I have the following data in R. training = factor(c(1,1,3,2,1,3,2,34,67,34)) test =
Let's say I have form looks like First: Use jQuery to display data like
Let's say I submit a form with anything in the value of user_input like
Let's say I have the following scenario: <form action=/something.php method=GET>Click me</div> <script type=text/javascript><!-- $('form').submit(function(e)
I'm checking my form with RSV validator. Want to get work following: Let's say
From the database, I load some data that user can edit. Let's say we
Let say I have an array like: Array ( [0] => Array ( [Data]
Can i send a input value into form action ?Let say, on the form

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.