Jump to content

Ajax status of response question


Gman7

Recommended Posts

Hello, I'm building a simple web application that involves the following function being invoked on the click of a button.

 

function signUp().
{
var username = document.getElementById('username').value;
var pass = document.getElementById('password').value;
var xmlhttp = new XMLHttpRequest();									
xmlhttp.onreadystatechange=function()
    {
	if (xmlhttp.readyState==4)
	{
		if (xmlhttp.status==200)
		{
			document.getElementById('username').value = 'asd';
			document.getElementById('password').value = '';
		}
	}
}
xmlhttp.open('GET','http://127.0.0.1/bookmark/newuser.php?username='+username+'&&pass='+pass,true);									
xmlhttp.send();
}

 

The request is sent to the following PHP page.

 

<?php
$uname = $_GET[username];
$pass = $_GET[pass];
$con = mysql_connect("localhost","gman","asdf");
if (!$con)
  {
die('Could not connect: ' . mysql_error());
  }
mysql_select_db("bookmarker", $con);
$sql="INSERT INTO users (username, pass)
VALUES('$uname','$pass')";
if (!mysql_query($sql,$con))
  {
die('Error: ' . mysql_error());
  }
else
  {
echo "BAZINGA!";
  }
mysql_close($con);
?>

 

The problem I'm having is that the response status is never 200. I've checked my database, and the Users table is getting updated with the entries regularly, however, the response never arrives for some reason.

 

Could someone please point out anything I'm doing wrong here? Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/209085-ajax-status-of-response-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.