使用javascript更改包含方向

时间:2013-06-24 02:24:53

标签: php javascript html

我正在尝试使用JavaScript更改包含路径。需要从这个

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

到这个

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

到这个

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

等等......有人知道如何用JavaScript编写代码吗?

2 个答案:

答案 0 :(得分:1)

您无法通过javascript更改PHP的编码方式。您可以通过javascript将变量发送到php,然后PHP响应这些变量......看起来您已经注册了各种类型。如果您正在使用标准HTTP请求,则可以使用javascript将$ _GET变量附加到操作链接。对于实例:

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

然后,点击链接后,PHP将可以访问$ _GET ['page'],所以在php中你可以:

 switch($_GET['page'])) {
     case 'welcome':
         include 'section/welcome.html';
         break;
     case 'nda':
         include 'section/nda.html';
         break;
 }

答案 1 :(得分:0)

看看下面的if(消息=== 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>';
               }
           }

       }
   }




}