hi i have these 3 files that use of ajax for redirect:

page1.php

<? 
if(isset($_POST['B1']))
{
header("location: page2.php");
die();
}

?>
<html> 

<head> 
<meta http-equiv="Content-Language" content="en-us"> 
<title>Ajax Example 1</title> 

<script src="ajax.js"></script> 

</head> 

<body> 

<form onSubmit="return AjaxSubmitForm(this);"> 
<p> 
   <input type="text" name="TextBox1"> 
   <input type="submit" value="Submit" name="B1"> 
   <input type="reset" value="Reset" name="B2"> 
</p> 
</form> 

<div id="Result"></div> 

</body> 

</html>

ajax.js

/* ---------------------------------------------------------------------------- */ 

function GetXmlHttpRequest() 
{ 
   var XmlHttpReq; 

   var msxmlhttp = new Array( 
      'Msxml2.XMLHTTP.5.0', 
      'Msxml2.XMLHTTP.4.0', 
      'Msxml2.XMLHTTP.3.0', 
      'Msxml2.XMLHTTP', 
      'Microsoft.XMLHTTP'); 
   for (var i = 0; i != msxmlhttp.length; i++) 
   { 
      try { 
         XmlHttpReq = new ActiveXObject(msxmlhttp[i]); //For IE 
      } catch (e) { 
         XmlHttpReq = null; 
      } 
   } 

   if(!XmlHttpReq ) 
      XmlHttpReq = new XMLHttpRequest();//For NS 

   return XmlHttpReq; 

} 

/* ---------------------------------------------------------------------------- */ 

function AjaxSubmitForm(FrmObject) 
{ 
   var Data; 

   Data = "&TextBox1=" + FrmObject.TextBox1.value + "&B1=" + FrmObject.B1.value; 

   PostData(Data, 'page1.php'); 

   return false; 
} 

/* ---------------------------------------------------------------------------- */ 

function PostData(Data, Url) 
{ 

   var XmlHttpReq = GetXmlHttpRequest(); 

   if(!XmlHttpReq) 
   { 
      alert('Your Browser not support AJAX!'); 
      return false; 
   } 

   XmlHttpReq.open("POST", Url, true); 

   XmlHttpReq.onreadystatechange = function() 
   { 
      if(XmlHttpReq.readyState == 4 && XmlHttpReq.status == 200)    
PrintResult(XmlHttpReq.responseText); }; XmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); XmlHttpReq.send(Data); return true; } /* ---------------------------------------------------------------------------- */ function PrintResult(TheData) { window.document.getElementById('Result').innerHTML = TheData; } /* ---------------------------------------------------------------------------- */

page2.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
Page 2 
</body>
</html>

Please test it. problem is when page1 redirected to page2, then the content of page1 repeated in page2 (also after redirecting the url doesn't changing and stay on page1.php)

any one can help me please?

    if fact my goal in page1.php is:

    <? 
    if(isset($_POST['B1'])) 
    { 
    if ($_POST['TextBox1']=="hello") echo "hello";
    else header("location: page2.php"); 
    die(); 
    } 
    ?>
    ...........
    

    but header doesn't redirect page1.php to page2.php
    what do i do?

      Roger Ramjet wrote:

      Basic else syntax error.

      Really? I can't find any syntax errors... goes to test server Yeah, syntax seems fine.

        after researching i can reach to success
        we have 2 changing

        page1.php

        <? 
        if(isset($_POST['B1'])) 
        { 
        if ($_POST['TextBox1']=="hello") echo "hello"; 
        else echo "redirect"; 
        die(); 
        } 
        ?> 
        ........... 
        

        ajax.js

        ......
        
        function PrintResult(TheData) 
        { 
        
        
        var data_check = TheData.indexOf("redirect"); 
        if ( data_check != -1 ) top.location.href = 'page2.php';  
        else window.document.getElementById('Result').innerHTML = TheData; }
          Write a Reply...