/    Sign up×
Community /Pin to ProfileBookmark

Ajax works on wamp localhost, but not domain.

Hi all.
Basicly an application im writing, works perfectly on a wamp localhost, but it fails to complete an ajax HTTPRequest on my domain. Ive checked the domain supports both javascript and php. The file ajax is requesting, is in the same folder as the .js and frontend php. As far as i can tell, everything runs fine, until it gets to the serverside php file ajax is trying to do a request on. It dosent make it to the serverside php.

Please help.

Cheers.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscNov 18.2008 — Good start. Now more information. My suggestion is to use Firefox and download Firebug. Enable it for you site online and then take a close look at the AJAX call (if you haven't already, you may have done this).

What do you mean it doesn't make it to the php script? Is the JS throwing an error before that? Does it make a request and get a 400 error? Provide some more information with code.
Copy linkTweet thisAlerts:
@scratchyriceauthorNov 18.2008 — Ok, ive just run firebug on it, and it returns a 500 error, when it attempts to POST. What does this mean?
Copy linkTweet thisAlerts:
@aj_nscNov 18.2008 — Error in your code in the server side script (or improperly set permissions) is usually what the error code means. Can we see your ajax code? Also, you can check your error log (or ask your server admins to check it for you if you dont have access) to see what the 500 error was.
Copy linkTweet thisAlerts:
@scratchyriceauthorNov 18.2008 — This is the call i make from within a .js file
<i>
</i> makeHttpRequest("signupValidate.php", "signup_ValidateCallback", false, "POST",
"signup_FirstName=" + document.getElementById("signup_FirstName").value +
"&amp;signup_LastName=" + document.getElementById("signup_LastName").value +
"&amp;signup_EmailAddress=" + document.getElementById("signup_EmailAddress").value +
"&amp;signup_Password=" + document.getElementById("signup_Password").value +
"&amp;signup_PasswordRe=" + document.getElementById("signup_PasswordRe").value +
"&amp;signup_Gender=" + document.getElementById("signup_Gender").value +
"&amp;signup_DOBDay=" + document.getElementById("signup_DOBDay").value +
"&amp;signup_DOBMonth=" + document.getElementById("signup_DOBMonth").value +
"&amp;signup_DOBYear=" + document.getElementById("signup_DOBYear").value +
"&amp;signup_Submit=" + fullSubmit);


The makeHTTPRequest is stored in ajax.js which is here:
<i>
</i>function makeHttpRequest(url, callback_function, return_xml, method, postParameters)
{
var http_request = false;
if (window.XMLHttpRequest)
{ // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType)
{
http_request.overrideMimeType('text/xml');
}

<i> </i>}
<i> </i>else
<i> </i> if (window.ActiveXObject)
<i> </i> { // IE
<i> </i> try
<i> </i> {
<i> </i> http_request = new ActiveXObject("Msxml2.XMLHTTP");
<i> </i> }
<i> </i> catch (e)
<i> </i> {
<i> </i> try
<i> </i> {
<i> </i> http_request = new ActiveXObject("Microsoft.XMLHTTP");
<i> </i> }
<i> </i> catch (e)
<i> </i> {
<i> </i> }
<i> </i> }
<i> </i>}

<i> </i>if (!http_request)
<i> </i>{
<i> </i> alert('Browser doesn't support Ajax');
<i> </i> return false;
<i> </i>}

<i> </i>http_request.onreadystatechange = function() {
<i> </i> if (http_request.readyState == 4)
<i> </i> {
<i> </i> if (http_request.status == 200)
<i> </i> {
<i> </i> if (return_xml)
<i> </i> {
<i> </i> eval(callback_function + '(http_request.responseXML)');
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> eval(callback_function + '(http_request.responseText)');
<i> </i> }
<i> </i> }
<i> </i> }
}
http_request.open(method, url, true);
if (method=="GET")
{ <br/>
http_request.send(null);
}
else
{
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", postParameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(postParameters);
}

}

function getFromXml(xmlobj, tag)
{
return xmlobj.getElementsByTagName(tag)[0].childNodes[0].nodeValue;
}


And finally, here is the .php file the request is made on, signupValidate.php:
<i>
</i>&lt;?php
//Include the php lib
include "..phpLibslibMain.php";

<i> </i>//Create root
<i> </i>$signupValidateRoot = new root();

<i> </i>//Perform a validation on the signup details, and return any errors.
<i> </i>$signup_FirstName = $_REQUEST['signup_FirstName'];
<i> </i>$signup_LastName = $_REQUEST['signup_LastName'];
<i> </i>$signup_EmailAddress = $_REQUEST['signup_EmailAddress'];
<i> </i>$signup_Password = $_REQUEST['signup_Password'];
<i> </i>$signup_PasswordRe = $_REQUEST['signup_PasswordRe'];
<i> </i>$signup_Gender = $_REQUEST['signup_Gender'];
<i> </i>$signup_DOBDay = $_REQUEST['signup_DOBDay'];
<i> </i>$signup_DOBMonth = $_REQUEST['signup_DOBMonth'];
<i> </i>$signup_DOBYear = $_REQUEST['signup_DOBYear'];
<i> </i>$signup_Submit = $_REQUEST['signup_Submit'];

<i> </i>//Check date of birth
<i> </i>if ($signup_DOBDay == "Day:" || $signup_DOBMonth == "Month:" || $signup_DOBYear == "Year:")
<i> </i>{
<i> </i> $currentError = "You must provide your date of birth.";
<i> </i>}

<i> </i>//Check a gender has been input
<i> </i>if ($signup_Gender == "Gender:")
<i> </i>{
<i> </i> $currentError = "You must provide your gender.";
<i> </i>}

<i> </i>//Check a password exists
<i> </i>if ($signup_Password == "" &amp;&amp; $signup_PasswordRe == "")
<i> </i>{
<i> </i> $currentError = "You must provide a password.";
<i> </i>}

<i> </i>//Check the passwords match
<i> </i>if ($signup_Password != $signup_PasswordRe)
<i> </i>{
<i> </i> $currentError = "Password's must match.";
<i> </i>}

<i> </i>//First check the email addresses match
<i> </i>if ($signup_EmailAddress == "")
<i> </i>{
<i> </i> $currentError = "You must provide an email address.";
<i> </i>}

<i> </i>//Check last name
<i> </i>if ($signup_LastName == "")
<i> </i>{
<i> </i> $currentError = "You must provide your last name.";
<i> </i>}

<i> </i>//Check first name
<i> </i>if ($signup_FirstName == "")
<i> </i>{
<i> </i> $currentError = "You must provide your first name.";
<i> </i>}

<i> </i>//Check for full submition
<i> </i>if ($signup_Submit == "true" &amp;&amp; $currentError == "")
<i> </i>{
<i> </i> //Check the email address has not been taken
<i> </i> $currentDatabaseConnection = $signupValidateRoot-&gt;database-&gt;connect();
<i> </i> $currentQuery = "SELECT email FROM users WHERE email = '$signup_EmailAddress'";
<i> </i> $currentResult = mysql_query($currentQuery);
<i> </i> while($currentRow = (mysql_fetch_array($currentResult, MYSQL_ASSOC)))
<i> </i> {
<i> </i> //Set the email error
<i> </i> $currentError = "An account with that email address already exists, please enter another.";
<i> </i> }

<i> </i> if ($currentError == "")
<i> </i> {
<i> </i> $signupValidateRoot-&gt;database-&gt;connect();

<i> </i> //Add the new user to the database
<i> </i> $currentQuery = "INSERT INTO users (firstName, lastName, email, password, gender)
<i> </i> VALUES ('$signup_FirstName', '$signup_LastName', '$signup_EmailAddress',
<i> </i> '$signup_Password', '$signup_Gender')";
<i> </i> mysql_query($currentQuery);

<i> </i> //Send a validation email to the client
<i> </i> $Name = "Alex Reed";
<i> </i> $email = "[email protected]";
<i> </i> $recipient = "[email protected]";
<i> </i> $mail_body = "Thank you for signing up. You may now log on, from the Home page.";
<i> </i> $subject = "myINet Signup";
<i> </i> $header = "From: ". $Name . " &lt;" . $email . "&gt;rn";
<i> </i> mail($recipient, $subject, $mail_body, $header);

<i> </i> $currentError = "Account created. Please check your email to validate your account.";
<i> </i> }

<i> </i> //Close the db connection
<i> </i> $signupValidateRoot-&gt;database-&gt;disconnect();
<i> </i>}

<i> </i>//Echo the error
<i> </i>echo $currentError;
?&gt;


I am actualy on a free webserver atm, but it says it supports php + javascript + mysql. Im getting a proper server when my website is near completion.
×

Success!

Help @scratchyrice spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...