0

JavaScript でインクルード パスを変更しようとしています。これから行く必要があります

<?php include 'sections/welcome.php'; ?>

これに

<?php include 'sections/new_visitor.php'; ?>

これに

<?php include 'sections/nda.php'; ?>

など... JavaScriptでこれをコーディングする方法を知っている人はいますか?

4

2 に答える 2

1

you can't change how PHP is coded via javascript. You can send variables to php via javascript and then PHP responds to those variables... it looks like you have a registration of sorts. If you're using standard HTTP requests, you could use javascript to append a $_GET variable to the action link. For Instance:

 $('#form').attr('action', $('#form').attr('action') + '?page=welcome'); 

Then, upon clicking the link, PHP will have access to $_GET['page'], so in php you could:

 switch($_GET['page'])) {
     case 'welcome':
         include 'section/welcome.html';
         break;
     case 'nda':
         include 'section/nda.html';
         break;
 }
于 2013-06-24T02:42:14.703 に答える
0

以下の if(message ===1) ステートメントを見てください:) 初心者でごめんなさい :P

var xmlHttp = createXmlHttpRequestObject();

            function createXmlHttpRequestObject(){
                var xmlHttp;

                if(window.ActiveXObject){
                    try{
                       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
                    }catch(e){
                        xmlHttp = false;
                    }
                }else{
                    try{
                       xmlHttp = new XMLHttpRequest();
                    }catch(e){
                        xmlHttp = false;
                    } 
                }

                if(!xmlHttp){
                    alert("cat create that object hos");
                }



       function newuser(){
           if(xmlHttp.readyState ===0 || xmlHttp.readyState ===4){
             name = encodeURIComponent(document.getElementById('name').value);
             company = encodeURIComponent(document.getElementById('company').value);
             nationalities = encodeURIComponent(document.getElementById('nationality').value);
             phonenumber = encodeURIComponent(document.getElementById('phonenumber').value);
             queryString = "?name=" + name + "&?company=" + company + "&?nationalities=" + nationalities + "&?phonenumber=" + phonenumber + "&?URL= newuser";
             xmlHttp.open("GET", "/php/database.php?" + queryString, true);
             xmlHttp.onreadystatechange = handleServerResponse;
             xmlHttp.send(null);
           }else{
               setTimeout('newuser()', 1000);
           }
       }

       function handleServwerResponse(){
           if(xmlHttp.readyState ===4){
               if(xmlHttp.status === 200){
                   xmlResponse = xmlHttp.responseXML;
                   xmlDocumentElement = xmlResponse.documentElement;
                   message = xmlDocumentElement.firstChild.data;

                   if(message === 1){

//ここで関数を呼び出したいので、インクルード パスを変更できます

               }else{
                   document.getElementBy("underInput").innerHTML = 'User already exist klick to sign in here <p style="color:blue" onclick=""></p>';
               }
           }

       }
   }




}
于 2013-06-24T15:09:13.183 に答える