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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.