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

implementing ajax within the same php page

Expand Messages
  • hawodi
    Am trying to implement ajax in my some of my pages but am confused as to how to go about it. The page am working on has both the html markup and the php code.
    Message 1 of 6 , Aug 1, 2006
    • 0 Attachment
      Am trying to implement ajax in my some of my pages but am confused as
      to how to go about it. The page am working on has both the html markup
      and the php code. Once the submit button is clicked, the form action
      reloads page to excute the php script on the page.

      All the ajax example I have seen so far have separate codes for the
      html mark up and a separate php page. Is it not possible for the ajax
      script to call the same page?

      Thanks
    • Tony Bibbs
      Yes, but you need to do something like a switch statement: if ($_POST[ action ] == doAjaxCmd ) { // do what ever ajax wizardry you want } else { // show the
      Message 2 of 6 , Aug 1, 2006
      • 0 Attachment
        Yes, but you need to do something like a switch statement:

        if ($_POST['action'] == 'doAjaxCmd') {
        // do what ever ajax wizardry you want
        } else {
        // show the initial page
        }

        I personally see this as bad design. What YUI component are you trying
        to use?

        --Tony

        hawodi wrote:
        >
        >
        > Am trying to implement ajax in my some of my pages but am confused as
        > to how to go about it. The page am working on has both the html markup
        > and the php code. Once the submit button is clicked, the form action
        > reloads page to excute the php script on the page.
        >
        > All the ajax example I have seen so far have separate codes for the
        > html mark up and a separate php page. Is it not possible for the ajax
        > script to call the same page?
        >
        > Thanks
        >
        >
      • Ken Robinson
        ... Sure, it s no different than invoking the same script for any other purpose, just pass some way of identifying that you re being invoked via AJAX, process
        Message 3 of 6 , Aug 1, 2006
        • 0 Attachment
          At 12:05 PM 8/1/2006, hawodi wrote:
          >Am trying to implement ajax in my some of my pages but am confused as
          >to how to go about it. The page am working on has both the html markup
          >and the php code. Once the submit button is clicked, the form action
          >reloads page to excute the php script on the page.
          >
          >All the ajax example I have seen so far have separate codes for the
          >html mark up and a separate php page. Is it not possible for the ajax
          >script to call the same page?

          Sure, it's no different than invoking the same script for any other
          purpose, just pass some way of identifying that you're being invoked
          via AJAX, process the information, and exit.

          I usually use a GET parameter for this purpose.

          Ken
        • Awodi H
          Thanks all for fast comments...this group is really responsive. Here is the code I am trying to use to implement ajax so that users it opens a new page:
          Message 4 of 6 , Aug 1, 2006
          • 0 Attachment
            Thanks all for fast comments...this group is really responsive. Here is the code I am trying to use to implement ajax so that users it opens a new page:
             

            <?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" />
            </head>


            <body>
            <div id="header">

            <h1>SPortal </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 onclick="makeRequest();"><a href="?userType=Student">Login as Student</a></li>
              <li  onclick="makeRequest();"><a href="?userType=Applicant">Login as Applicant</a></li>
             
             
             
             </ul>
              </p>
            </div>

            </div>

            <div id="footer">&copy; skoolnet</div>

            </body>
            </html>

             

            I will be using the yui connect.
             
            Thanks.


             
            On 8/1/06, Ken Robinson <kenrbnsn@...> wrote:

            At 12:05 PM 8/1/2006, hawodi wrote:
            >Am trying to implement ajax in my some of my pages but am confused as
            >to how to go about it. The page am working on has both the html markup
            >and the php code. Once the submit button is clicked, the form action
            >reloads page to excute the php script on the page.
            >
            >All the ajax example I have seen so far have separate codes for the
            >html mark up and a separate php page. Is it not possible for the ajax
            >script to call the same page?

            Sure, it's no different than invoking the same script for any other
            purpose, just pass some way of identifying that you're being invoked
            via AJAX, process the information, and exit.

            I usually use a GET parameter for this purpose.

            Ken




            --
            Awodi Hassan

            Digital Quest Ltd
            1 Adegbeyeni Street, Off Allen Avenue,
            Ikeja-Nigeria.
            2341802 421 4493, 234-1-890 7456
          • Tony Bibbs
            ... I have no idea what you mean by that. Best as I can tell it looks like you are trying to use a JS function called makeRequest to log a user in? If so, I m
            Message 5 of 6 , Aug 1, 2006
            • 0 Attachment
              Awodi H wrote:
              > Thanks all for fast comments...this group is really responsive. Here is
              > the code I am trying to use to implement ajax so that users it opens a
              > new page:

              I have no idea what you mean by that. Best as I can tell it looks like
              you are trying to use a JS function called makeRequest to log a user in?
              If so, I'm not seeing that JS function anywhere in the code.

              --Tony
            • Awodi H
              oops, forgot to include the ajax js part. We upload later thanks tony. ... -- Awodi Hassan Digital Quest Ltd 1 Adegbeyeni Street, Off Allen Avenue,
              Message 6 of 6 , Aug 1, 2006
              • 0 Attachment
                oops, forgot to include the ajax js part. We upload later thanks tony.

                On 8/1/06, Tony Bibbs <tony@... > wrote:

                Awodi H wrote:
                > Thanks all for fast comments...this group is really responsive. Here is
                > the code I am trying to use to implement ajax so that users it opens a
                > new page:

                I have no idea what you mean by that. Best as I can tell it looks like
                you are trying to use a JS function called makeRequest to log a user in?
                If so, I'm not seeing that JS function anywhere in the code.

                --Tony




                --
                Awodi Hassan

                Digital Quest Ltd
                1 Adegbeyeni Street, Off Allen Avenue,
                Ikeja-Nigeria.
                2341802 421 4493, 234-1-890 7456
              Your message has been successfully submitted and would be delivered to recipients shortly.