I'm Working with register module with xmlHttpRequest. I have checking all. When i was trying to redirect after successfull its displaying the response with in the given div.

<script type="text/javascript">
		function showRegister()
		{
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			document.getElementById("result").innerHTML=xmlhttp.responseText;
			}
		  }
		  
		  var fname = document.getElementById("userfname").value;
		  var lname = document.getElementById("userlname").value;
		  var email = document.getElementById("userfemail").value;
		  var pass = document.getElementById("userfpass").value;
		  var gender = document.getElementById("userfgender").value;
		  var umonth = document.getElementById("usermonth").value;
		  var uday = document.getElementById("userday").value;
		  var uyear = document.getElementById("useryear").value;
		  var tc = document.getElementById("tc").checked;
		  
		  var registervalues = "fname=" + fname + "&lname=" + lname + "&email=" + email + "&pass=" + pass + "&gender=" + gender + "&umonth=" + umonth + "&uday=" + uday + "&uyear=" + uyear + "&tc=" + tc + "";
		  
		xmlhttp.open("POST","checkregister.php",true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send(registervalues);
		}
		</script>
<?php
	$fname = $_POST['fname'];
	$lname = $_POST['lname'];
	$email = $_POST['email'];
	$pass = $_POST['pass'];
	$gender = $_POST['gender'];
	$month = $_POST['umonth'];
	$day = $_POST['uday'];
	$year = $_POST['uyear'];
	$terms = $_POST['tc'];
	
	if($fname == "" || $lname == "" || $email == "" || $pass == ""){
		echo "<p style='padding: 3px; text-align: center; border: 1px solid red;'>Please fill all the details</p>";
	}
	else if($month == "Month" || $day == "day" || $year == "Year"){
		echo "<p style='padding: 3px; text-align: center; border: 1px solid red;'>You must indicate your full birthday to register</p>";
	}
	else if($terms == "false" || $terms == FALSE){
		echo "<p style='padding: 3px; text-align: center; border: 1px solid red;'>You must agree our terms & conditions</p>";
	}
	else{
		header("Location: profile.html");
		exit;
	}
?>

Please help me ..

Recommended Answers

All 4 Replies

Member Avatar for stbuchok

Can you clarify as to what the issues is?

You are trying to redirect in a PHP file that is called via AJAX. That won't work. You should return redirect info to your AJAX call, so you can redirect using Javascript in your 200 success function.

can you give me an example for 200 success function ?

It's what's on your line 16 in your Javascript code above.

You need to somehow detect there that you have to redirect, and act accordingly. I think your best bet is to let your PHP file return a JSON result (instead of just HTML).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.