2013-06-24 37 views
0

我正在嘗試使用JavaScript更改包含路徑。它需要對從該使用javascript更改包含方向

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

去這個

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

這個

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

等等...不要有人知道如何在JavaScript代碼呢?

回答

1

您無法更改PHP是如何通過javascript進行編碼的。你可以通過javascript發送變量到PHP,然後PHP響應這些變量......它看起來像你有一個排序註冊。如果您使用標準HTTP請求,則可以使用javascript將$ _GET變量附加到操作鏈接。比如:

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

然後,當點擊該鏈接,PHP將有機會獲得$ _GET [ '頁'],所以在PHP中您可以:

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

這就是我們如何爲我們的CRM系統做的,所以我第二種方法 – RussellHarrower

+0

ok!謝謝:D,但我怎麼連接這個feks。一個提交按鈕? – user2514718

+0

嗯....我不確定你在問什麼:連接到feks。一個提交按鈕? –

0

看的,如果(消息= == 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>'; 
       } 
      } 

     } 
    } 




} 
+0

我不確定你想要做什麼。如果您只是試圖更改服務器返回的數據,則應該讓服務器從最初的ajax調用中返回適當的數據。編寫你的服務器返回,返回javascript需要的數據,而不是返回一個狀態,並讓JavaScript嘗試改變包含的內容。在你的例子中,消息=== 1,你可以寫,而不是消息==='無論內容JavaScript需要'? –