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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:00:53+00:00 2026-05-15T07:00:53+00:00

I have another question. XMLhttpRequests haunt me. Everything is now in the database but

  • 0

I have another question. XMLhttpRequests haunt me. Everything is now in the database but I need this data to update my page on firt page load or reload. The XHR is triggered in JavaScript file which triggers PHP-Script. PHP-Script access MySQL database. But how do I get the fetched records back into my JavaScript for page update. I can not figure it out.

First my synchronous XMLhttpRequest:

function retrieveRowsDB()
{
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari

     xmlhttp=new XMLHttpRequest();

  }
  else
  {// code for IE6, IE5
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

  xmlhttp.open("GET","retrieveRowData.php", false);
  xmlhttp.send(null);

  return xmlhttp.responseText;
}

Then my PHP-Script:

<?php

 $con = mysql_connect("localhost","root","*************");
 if (!$con)
 {
   die('Could not connect: ' . mysql_error());
 }

 mysql_select_db("sadb", $con);

 $data="SELECT * FROM users ORDER BY rowdata ASC";

 if (!mysql_query($data,$con))
 {
  die('Error: ' . mysql_error());
 }
 else
 {
  $dbrecords = mysql_query($data,$con); 
 }

 $rowdata = mysql_fetch_array($dbrecords);

 return $rowdata;

        mysql_close($con);

?>

What am I missing here? Anyone got a clue?

  • 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-15T07:00:54+00:00Added an answer on May 15, 2026 at 7:00 am

    There’s not much technically wrong with your code so far – you just need to actually do something with it.

    In your PHP file, instead of return $rowdata;, you need to output it in some way. Currently, it’s just sending a blank document back to the javascript, so you’ll need to echo out the code. Normally, when using a number of objects to be returned to javascript, JSON is a good format. Check out json_encode.

    On the other side, in the js, you’ll need to take the response and update the page in some manner. Currently, you’re just returning it again.

    I suggest you go through a few ajax tutorials, and consider using a framework such as jQuery to do the heavy lifting for you. You might also want to do a bit of reading on this topic, as you have some fundamental misconceptions.

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

Sidebar

Related Questions

I have already posted another question about this, but no one seemed to know
I have another question, which i'll be asking shortly, but to ask this question
I have another question kind of relative to this but I'd like to separate
Another question related to this one . I have a List<SortableObjects> that is the
Ok I have another question HERE for my Logging Class but I wanted to
ok, i have another question now. I have a bunch of beans loaded succesfully
Ok I have another question and I'm a beginner at this. I have this
I have another question, not sure if this would be accomplished via PHP or
I have another question for the brilliant minds out there (this site is so
I have another question about restoring application state, on the iPhone. Simple data (like

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.