Jump to content


Photo

re-direct php page with ajax

ajax php html

  • Please log in to reply
5 replies to this topic

#1 Pawan_Agarwal

Pawan_Agarwal

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts
  • LocationIndia

Posted 11 May 2014 - 09:47 PM

I know how to implement ajax with php and get output with the help of java-script and ajax...

 

Well, I am just trying to re-direct the page using ajax, but, it is not happening........

 

What I am doing is that after user logged-in successfully, the email and password are going to check by ajax and if the inputs are correct, the page must re-direct to another page...

 

So, far I am able to verify the correct details, but, the page is not re-directing... You must also see that I want to re-direct the page with ajax only................I am able to redirect the page with java-script but I do not want to include re-direction with java-script in my website !!

 

Thanks for helping me out !! 



#2 trq

trq

    Advanced Member

  • Administrators
  • 30,892 posts
  • LocationSydney, Australia.

Posted 11 May 2014 - 11:33 PM

Redirecting a page with Ajax? That makes no sense at all.

Do you know what Ajax is?

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.


#3 Pawan_Agarwal

Pawan_Agarwal

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts
  • LocationIndia

Posted 12 May 2014 - 06:07 AM

I have java -script code 

 

<script type="text/javascript">
function findName()
{
 str = document.getElementById("num").value;
 
 var xmlhttp;
if (str=="")
  {
  document.getElementById("answer").innerHTML="";
  return;
  }
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("answer").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","details.php?q="+str,true);
xmlhttp.send();
}
</script>
 
################### details.php ################### 
<?php
echo $_REQUEST['q'];
?>
################### details.php ################### 
 
when user click on button, details.php execute and it prints on the page , I understand this as ajax


#4 trq

trq

    Advanced Member

  • Administrators
  • 30,892 posts
  • LocationSydney, Australia.

Posted 12 May 2014 - 07:02 AM

So, how does it make sense to use ajax to redirect a user to another page?

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.


#5 Pawan_Agarwal

Pawan_Agarwal

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts
  • LocationIndia

Posted 13 May 2014 - 09:46 PM

You know well, how gmail redirects page after login, I want to have the same feature ...



#6 davidannis

davidannis

    Freak Dr.

  • Members
  • PipPipPip
  • 563 posts
  • LocationOkemos, MI USA

Posted 14 May 2014 - 10:45 AM

I think you should just submit and use php header() to redirect. Using Ajax is great to save time and bandwidth so the entire page need not be retransmitted from the server but there is no advantage to using it to redirect since after the redirect the server will transmit the entire page anyway. Even if you can get it to work it does not save you time or bandwidth.


Edited by davidannis, 14 May 2014 - 10:47 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com