Asked  7 Months ago    Answers:  5   Viewed   42 times

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();

  {// code for IE6, IE5
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }"GET","retrieveRowData.php", false);

  return xmlhttp.responseText;

Then my PHP-Script:


 $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());
  $dbrecords = mysql_query($data,$con); 

 $rowdata = mysql_fetch_array($dbrecords);

 return $rowdata;



What am I missing here? Anyone got a clue?



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.

Saturday, May 29, 2021
answered 7 Months ago

You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer.

This blog post has all the details (with pictures) to successfully configure IDE for such scenario:

Related usability ticket:

P.S. The WI-18388 ticket is already fixed in v8.0

Wednesday, March 31, 2021
answered 9 Months ago

Sounds like you're experiencing quite a well-known issue (some info here: PHP "php://input" vs $_POST)

You should be able to access the data with file_get_contents('php://input')

Wednesday, March 31, 2021
answered 9 Months ago

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Saturday, May 29, 2021
answered 7 Months ago

The problem is this line:

if (heatControlRequest.readystate == 4){
                            ^ this should be an uppercase S

It should be:

if (heatControlRequest.readyState == 4){ 

From the docs:

The XMLHttpRequest object can be in several states. The readyState attribute must return the current state.

Saturday, May 29, 2021
answered 7 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :