Loading ...
Sorry, an error occurred while loading the content.

opening another page using ajax

Expand Messages
  • hawodi
    Been trying to use ajax on page that will send post parameters to another page which in turn will open up a login page. So far code works but it doesn t
    Message 1 of 1 , Aug 2, 2006
    • 0 Attachment
      Been trying to use ajax on page that will send post parameters to
      another page which in turn will open up a login page.

      So far code works but it doesn't display the page even though I can
      see the return contents via firefox webdeveloper tool.

      The login page is on another site(http://localhost/skoolmaster), the
      intro page is (http://localhost/skoolnet) but they are all on the same
      machine.


      Here is the code:

      <?php
      include_once('ezpdo_runtime.php');
      include_once('userFunctions.inc.php');
      session_start();

      // get the persistence manager
      $m = epManager::instance();


      if(($userType=@$_REQUEST['userType']) || @$_POST['username']){ //login
      attempt
      $access_page='';

      //retrieve school info
      $schools=$m->getAll('School');
      foreach($schools as $school)

      //retrieve the current school session
      $schSessions=$m->find("from School_Session where 1 order by oid desc");
      foreach($schSessions as $currentSchSession){break;}

      switch ($userType) {
      case 'Applicant':
      case 'Student':

      //get the translated path of this page

      $_SESSION['openerUrl']='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
      $_SESSION['schoolId']=$school->schoolId;

      $access_page=$school->masterUrl;

      break;

      default:
      //Staff
      $userId=$_POST['username'];
      $pwd=$_POST['password'];
      $loginRole=$_POST['loginRole'];

      //Search for current user role
      if ($userRoles = $m->find("from Role where role = ?",
      $loginRole)){
      foreach($userRoles as $userRole);
      }

      //Search for current user info
      if ($users = $m->find("from Staff where username = ?",
      $userId)) {
      foreach($users as $user)
      if($user->password!=$pwd) $login_failure_msg='<font
      color="red">Invalid password</font>';
      else{
      if($user->roles->inArray($userRole)){
      //access granted
      $access_page=getStaffAccessPage($loginRole);
      $_SESSION['obj_user']=$user;
      }
      else
      //access denied
      $login_failure_msg='<font color="red">Access denied!<br>You do
      not have a "'.$loginRole.'" role.</font>';
      }
      }
      else $login_failure_msg='<font color="red">Invalid
      username</font>';

      break;

      }//end switch user type

      if($access_page){//load user access page
      if(@$currentSchSession)
      $_SESSION['schSession']=$currentSchSession->session;
      header('Location: '.$access_page);
      }

      } //end login attempt

      ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>position</title>

      <link href="skoolnet.css" rel="stylesheet" type="text/css" />
      <script src="js/yahoo.js"></script>
      <script src="js/connection.js"></script>

      <script>
      //var div=document.getElementById('content');
      var handleSuccess = function(o){
      if(o.responseText !== undefined){
      /*div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
      div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
      div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
      div.innerHTML += "<li>HTTP headers received: <ul>" +
      o.getAllResponseHeaders + "</ul></li>";
      div.innerHTML += "<li>PHP response: " + o.responseText + "</li>";
      div.innerHTML += "<li>Argument object: Array ([0] => " + o.argument[0] +
      " [1] => " + o.argument[1] + " )</li>";*/
      }
      };

      var handleFailure = function(o){
      if(o.responseText !== undefined){
      div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
      div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
      div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
      }
      };

      var callback =
      {
      success:handleSuccess,
      failure:handleFailure,
      argument:['foo','bar']
      };

      var sUrl = "http://localhost/skoolmaster";
      var postData;

      function makeRequest(usertype){
      postData=usertype;
      var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback,
      postData);
      }
      </script>

      </head>


      <body>
      <div id="header">

      <h1>SkoolNet University Portal </h1>

      </div>
      <div id="container">
      <div id="content">
      <p>Pls enter your information</p>
      </div>

      <div id="left_nav">
      <p id="login_page">
      <?php
      if(@$_SESSION['noAccess']){
      echo $_SESSION['noAccess'];
      session_unregister('noAccess');
      }
      ?>

      <ul >
      <li ><a onclick="makeRequest('Student');" href="#"><span
      id="student">Login as Student</span></a></li>
      <li onclick="makeRequest();" id="applicant"><a
      href="?userType=Applicant">Login as Applicant</a></li>



      </ul>
      </p>
      </div>

      </div>

      <div id="footer">© skoolnet</div>

      </body>
      </html>
    Your message has been successfully submitted and would be delivered to recipients shortly.