Jump to content

[SOLVED] Server Request Becoming Null


DRock

Recommended Posts

This one has been bugging me all night. I have used Ajax quite a bit before but I can't figure out why this doesn't work. The problem is at www.ymsrunning.com when you click the "Email Updates" link and enter an email in the form. The form calls the following JS function:

 

function addEmail(form)

{

var email = form.email.value;

 

if ((email.indexOf(".") > 2) && (email.indexOf("@") > 0))

{

var url = "signup.php";

request.open("POST", url, true);

request.onreadystatechange = updateEmail;

request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

  request.send("email=" + email);

}

else

alert("You did not enter a valid email address.");

}

 

function updateEmail()

{

if (request.readyState == 4)

{

            if (request.status == 200)

{

var response = request.responseText;

alert(response);

}

else

alert("Error! Request status is " + request.status);

}

}

 

The request variable exists up until the if statement checking for 200 status. If I check the status at that point it is always 0, but the variable is not null before that line. Once the line runs JS generates an error stating request is null. I am pulling my hair out with this one, and I tried running the PHP file on its own and it doesn't generate any errors. I would really appreciate any help. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/155589-solved-server-request-becoming-null/
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.